Skip to main content

vortex_io/runtime/
current.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use std::future::Future;
5use std::sync::Arc;
6
7use async_channel::TryRecvError;
8use futures::SinkExt;
9use futures::Stream;
10use futures::StreamExt;
11use futures::channel::mpsc;
12use futures::stream::BoxStream;
13use parking_lot::Mutex;
14use smol::block_on;
15use vortex_utils::parallelism::get_available_parallelism;
16
17use crate::runtime::BlockingRuntime;
18use crate::runtime::Executor;
19use crate::runtime::Handle;
20pub use crate::runtime::pool::CurrentThreadWorkerPool;
21use crate::runtime::smol::SmolExecutor;
22
23/// A current thread runtime allows callers to much more explicitly drive Vortex futures than with
24/// a Tokio runtime.
25///
26/// The current thread runtime will do no work unless `block_on` is called. In other words, the
27/// default behavior is single-threaded with code running on the thread that called `block_on`.
28///
29/// It's also possible to clone the runtime onto other threads, each of which can call `block_on`
30/// to drive work on that thread. Each thread shares the same underlying executor with the same
31/// set of tasks, allowing work to be driven in parallel.
32///
33/// For automatic driving of work, a [`CurrentThreadWorkerPool`] can be created from the runtime
34/// by calling [`new_pool`](CurrentThreadRuntime::new_pool). The returned pool can be configured
35/// with the desired number of worker threads that will drive work on behalf of the runtime.
36#[derive(Clone, Default)]
37pub struct CurrentThreadRuntime {
38    executor: Arc<SmolExecutor>,
39}
40
41impl CurrentThreadRuntime {
42    /// Create a new current thread runtime.
43    pub fn new() -> Self {
44        Self::default()
45    }
46
47    /// Create a new worker pool for driving the runtime in the background.
48    ///
49    /// This pool can be used to offload work from the current thread to a set of worker threads
50    /// that will drive the runtime's executor.
51    ///
52    /// By default, the pool has no worker threads; the caller must set the desired number of
53    /// worker threads using the `set_workers` method on the returned pool.
54    pub fn new_pool(&self) -> CurrentThreadWorkerPool {
55        CurrentThreadWorkerPool::new(Arc::clone(&self.executor))
56    }
57
58    /// Returns an iterator wrapper around a stream, blocking the current thread for each item.
59    ///
60    /// ## Multi-threaded Usage
61    ///
62    /// To drive the iterator from multiple threads, simply clone it and call `next()` on each
63    /// clone. Results on each thread are ordered with respect to the stream, but there is no
64    /// ordering guarantee between threads.
65    pub fn block_on_stream_thread_safe<F, S, R>(&self, f: F) -> ThreadSafeIterator<R>
66    where
67        F: FnOnce(Handle) -> S,
68        S: Stream<Item = R> + Send + 'static,
69        R: Send + 'static,
70    {
71        let stream = f(self.handle());
72
73        // We create an MPMC result channel and spawn a task to drive the stream and send results.
74        // This allows multiple worker threads to drive the execution while all waiting for results
75        // on the channel. Channel buffers up to one item per core so calling threads can get a
76        // ready item without every one of them having to become an executor.
77        let capacity = get_available_parallelism().unwrap_or(1).max(1);
78        let (result_tx, result_rx) = async_channel::bounded(capacity);
79        let driver = self.executor.async_executor().spawn(async move {
80            futures::pin_mut!(stream);
81            while let Some(item) = stream.next().await {
82                // If all receivers are dropped, we stop driving the stream.
83                if let Err(e) = result_tx.send(item).await {
84                    tracing::trace!("all receivers dropped, stopping stream: {}", e);
85                    break;
86                }
87            }
88        });
89
90        ThreadSafeIterator {
91            executor: Arc::clone(&self.executor),
92            results: result_rx,
93            driver: Arc::new(Mutex::new(Some(driver))),
94        }
95    }
96
97    /// Returns an iterator that drives a stream in a background task, keeping at most one
98    /// completed item ready ahead of the single consumer.
99    ///
100    /// Use this instead of [`block_on_stream_thread_safe`](Self::block_on_stream_thread_safe)
101    /// when items are large and a per-core output queue would retain too many of them.
102    pub fn block_on_stream_prefetch<S, R>(&self, stream: S) -> PrefetchIterator<R>
103    where
104        S: Stream<Item = R> + Send + 'static,
105        R: Send + 'static,
106    {
107        // A zero-capacity mpsc still gives the sender one slot, and `send` resolves only once the
108        // receiver takes the item, so the driver never pulls a second item ahead.
109        let (mut result_tx, result_rx) = mpsc::channel(0);
110        let driver = self.executor.async_executor().spawn(async move {
111            futures::pin_mut!(stream);
112            while let Some(item) = stream.next().await {
113                if result_tx.send(item).await.is_err() {
114                    break;
115                }
116            }
117        });
118
119        PrefetchIterator {
120            executor: Arc::clone(&self.executor),
121            results: result_rx,
122            driver: Some(driver),
123        }
124    }
125}
126
127impl BlockingRuntime for CurrentThreadRuntime {
128    type BlockingIterator<'a, R: 'a> = CurrentThreadIterator<'a, R>;
129
130    fn handle(&self) -> Handle {
131        let executor: Arc<dyn Executor> = Arc::clone(&self.executor) as Arc<dyn Executor>;
132        Handle::new(Arc::downgrade(&executor))
133    }
134
135    fn block_on<Fut, R>(&self, fut: Fut) -> R
136    where
137        Fut: Future<Output = R>,
138    {
139        block_on(self.executor.run(fut))
140    }
141
142    fn block_on_stream<'a, S, R>(&self, stream: S) -> Self::BlockingIterator<'a, R>
143    where
144        S: Stream<Item = R> + Send + 'a,
145        R: Send + 'a,
146    {
147        CurrentThreadIterator {
148            executor: Arc::clone(&self.executor),
149            stream: stream.boxed(),
150        }
151    }
152}
153
154/// An iterator that wraps up a stream to drive it using the current thread execution.
155pub struct CurrentThreadIterator<'a, T> {
156    executor: Arc<SmolExecutor>,
157    stream: BoxStream<'a, T>,
158}
159
160impl<T> Iterator for CurrentThreadIterator<'_, T> {
161    type Item = T;
162
163    fn next(&mut self) -> Option<Self::Item> {
164        block_on(self.executor.run(self.stream.next()))
165    }
166}
167
168/// An iterator that drives a stream from multiple threads.
169pub struct ThreadSafeIterator<T> {
170    executor: Arc<SmolExecutor>,
171    results: async_channel::Receiver<T>,
172    /// Handle to the task driving the stream. Once the stream ends, the first consumer to
173    /// observe it joins the task so a panic raised while driving the stream is re-raised rather
174    /// than silently ending the iterator.
175    driver: Arc<Mutex<Option<smol::Task<()>>>>,
176}
177
178// Manual clone implementation since `T` does not need to be `Clone`.
179impl<T> Clone for ThreadSafeIterator<T> {
180    fn clone(&self) -> Self {
181        Self {
182            executor: Arc::clone(&self.executor),
183            results: self.results.clone(),
184            driver: Arc::clone(&self.driver),
185        }
186    }
187}
188
189impl<T> Iterator for ThreadSafeIterator<T> {
190    type Item = T;
191
192    fn next(&mut self) -> Option<Self::Item> {
193        // If driver already has an item, take it without driving the executor
194        match self.results.try_recv() {
195            Ok(item) => return Some(item),
196            Err(TryRecvError::Empty) => {}
197            Err(TryRecvError::Closed) => return self.get_task_error(),
198        }
199
200        match block_on(self.executor.run(self.results.recv())) {
201            Ok(item) => Some(item),
202            Err(_) => self.get_task_error(),
203        }
204    }
205}
206
207impl<T> ThreadSafeIterator<T> {
208    // Join current task so panics are re-raised
209    fn get_task_error(&self) -> Option<T> {
210        let task = self.driver.lock().take();
211        if let Some(task) = task {
212            block_on(self.executor.run(task));
213        }
214        None
215    }
216}
217
218/// A single-consumer iterator that keeps at most one completed item ahead of the consumer.
219pub struct PrefetchIterator<T> {
220    executor: Arc<SmolExecutor>,
221    results: mpsc::Receiver<T>,
222    /// Joined once the stream ends so a panic raised while driving it is re-raised.
223    driver: Option<smol::Task<()>>,
224}
225
226impl<T> Iterator for PrefetchIterator<T> {
227    type Item = T;
228
229    fn next(&mut self) -> Option<Self::Item> {
230        let item = match self.results.try_recv() {
231            Ok(item) => Some(item),
232            Err(mpsc::TryRecvError::Closed) => None,
233            Err(mpsc::TryRecvError::Empty) => block_on(self.executor.run(self.results.next())),
234        };
235        if item.is_none()
236            && let Some(driver) = self.driver.take()
237        {
238            block_on(self.executor.run(driver));
239        }
240        item
241    }
242}
243
244#[cfg(test)]
245mod tests {
246    use std::any::Any;
247    use std::panic::AssertUnwindSafe;
248    use std::sync::Arc;
249    use std::sync::Barrier;
250    use std::sync::atomic::AtomicUsize;
251    use std::sync::atomic::Ordering;
252    use std::task::Poll;
253    use std::thread;
254    use std::time::Duration;
255
256    use futures::StreamExt;
257    use futures::stream;
258    use parking_lot::Mutex;
259
260    use super::*;
261
262    #[test]
263    fn test_worker_thread() {
264        let runtime = CurrentThreadRuntime::new();
265
266        // We spawn a future that sets a value on a separate thread.
267        let value = Arc::new(AtomicUsize::new(0));
268        let value2 = Arc::clone(&value);
269        runtime
270            .handle()
271            .spawn(async move {
272                value2.store(42, Ordering::SeqCst);
273            })
274            .detach();
275
276        // By default, nothing has driven the executor, so the value should still be 0.
277        assert_eq!(value.load(Ordering::SeqCst), 0);
278
279        // An empty pool still does nothing.
280        let pool = runtime.new_pool();
281        assert_eq!(value.load(Ordering::SeqCst), 0);
282
283        // Adding a worker thread should drive the executor.
284        pool.set_workers(1);
285        for _ in 0..10 {
286            if value.load(Ordering::SeqCst) == 42 {
287                break;
288            }
289            thread::sleep(Duration::from_millis(10));
290        }
291        assert_eq!(value.load(Ordering::SeqCst), 42);
292    }
293
294    #[test]
295    fn test_block_on_stream_single_thread() {
296        let mut iter =
297            CurrentThreadRuntime::new().block_on_stream(stream::iter(vec![1, 2, 3, 4, 5]).boxed());
298
299        assert_eq!(iter.next(), Some(1));
300        assert_eq!(iter.next(), Some(2));
301        assert_eq!(iter.next(), Some(3));
302        assert_eq!(iter.next(), Some(4));
303        assert_eq!(iter.next(), Some(5));
304        assert_eq!(iter.next(), None);
305    }
306
307    #[test]
308    fn test_block_on_stream_multiple_threads() {
309        let counter = Arc::new(AtomicUsize::new(0));
310        let num_threads = 4;
311        let items_per_thread = 25;
312        let total_items = 100;
313
314        let iter = CurrentThreadRuntime::new()
315            .block_on_stream_thread_safe(|_h| stream::iter(0..total_items).boxed());
316
317        let barrier = Arc::new(Barrier::new(num_threads));
318        let results = Arc::new(Mutex::new(Vec::new()));
319
320        let threads: Vec<_> = (0..num_threads)
321            .map(|_| {
322                let mut iter = iter.clone();
323                let counter = Arc::clone(&counter);
324                let barrier = Arc::clone(&barrier);
325                let results = Arc::clone(&results);
326
327                thread::spawn(move || {
328                    barrier.wait();
329                    let mut local_results = Vec::new();
330
331                    for _ in 0..items_per_thread {
332                        if let Some(item) = iter.next() {
333                            counter.fetch_add(1, Ordering::SeqCst);
334                            local_results.push(item);
335                        }
336                    }
337
338                    results.lock().push(local_results);
339                })
340            })
341            .collect();
342
343        for thread in threads {
344            thread.join().unwrap();
345        }
346
347        assert_eq!(counter.load(Ordering::SeqCst), total_items);
348
349        let all_results = results.lock();
350        let mut collected: Vec<_> = all_results.iter().flatten().copied().collect();
351        collected.sort();
352        assert_eq!(collected, (0..total_items).collect::<Vec<_>>());
353    }
354
355    #[test]
356    fn test_block_on_stream_thread_safe_propagates_driver_panic() {
357        let runtime = CurrentThreadRuntime::new();
358        let mut iter = runtime.block_on_stream_thread_safe(|_h| {
359            stream::poll_fn(|_| -> Poll<Option<usize>> {
360                panic!("stream driver panic");
361            })
362            .boxed()
363        });
364
365        let panic = std::panic::catch_unwind(AssertUnwindSafe(|| iter.next()))
366            .expect_err("stream panic must propagate through iterator");
367        let message = panic
368            .downcast_ref::<&'static str>()
369            .copied()
370            .or_else(|| panic.downcast_ref::<String>().map(String::as_str))
371            .unwrap_or("<unknown panic>");
372        assert!(message.contains("stream driver panic"));
373    }
374
375    fn panic_message(panic: &(dyn Any + Send)) -> &str {
376        panic
377            .downcast_ref::<&'static str>()
378            .copied()
379            .or_else(|| panic.downcast_ref::<String>().map(String::as_str))
380            .unwrap_or("<unknown panic>")
381    }
382
383    // A driver panic must propagate on *every* run, regardless of executor scheduling. Running
384    // the scenario many times guards against a return to timing-dependent propagation.
385    #[test]
386    fn test_block_on_stream_thread_safe_panic_propagation_is_deterministic() {
387        for i in 0..2000 {
388            let mut iter = CurrentThreadRuntime::new().block_on_stream_thread_safe(|_h| {
389                stream::poll_fn(|_| -> Poll<Option<usize>> {
390                    panic!("deterministic driver panic");
391                })
392                .boxed()
393            });
394
395            let outcome = std::panic::catch_unwind(AssertUnwindSafe(|| iter.next()));
396            assert!(
397                outcome.is_err(),
398                "driver panic was swallowed on iteration {i}: next() returned {:?}",
399                outcome.ok().flatten(),
400            );
401        }
402    }
403
404    // A panic after some items were already produced must still surface, not be seen as a clean
405    // end of stream.
406    #[test]
407    fn test_block_on_stream_thread_safe_panic_after_items() {
408        let mut emitted = 0usize;
409        let iter = CurrentThreadRuntime::new().block_on_stream_thread_safe(move |_h| {
410            stream::poll_fn(move |_| -> Poll<Option<usize>> {
411                if emitted < 3 {
412                    emitted += 1;
413                    Poll::Ready(Some(emitted))
414                } else {
415                    panic!("driver panic after items");
416                }
417            })
418            .boxed()
419        });
420
421        // Drain the iterator. The terminal event must be a propagated panic, never a clean
422        // `None`. This avoids depending on exactly how many buffered items survive channel close.
423        let outcome = std::panic::catch_unwind(AssertUnwindSafe(move || iter.collect::<Vec<_>>()));
424        match outcome {
425            Ok(items) => panic!("driver panic was swallowed; stream ended cleanly with {items:?}"),
426            Err(panic) => assert!(panic_message(&*panic).contains("driver panic after items")),
427        }
428    }
429
430    // With multiple consumers, a driver panic must reach *every* consumer that observes the end
431    // of the stream; it must never be swallowed by all of them. Exactly one consumer joins the
432    // driver and observes the panic; the rest see the stream end.
433    #[test]
434    fn test_block_on_stream_thread_safe_multi_consumer_panic_surfaced() {
435        let iter = CurrentThreadRuntime::new().block_on_stream_thread_safe(|_h| {
436            stream::poll_fn(|_| -> Poll<Option<usize>> {
437                panic!("multi consumer driver panic");
438            })
439            .boxed()
440        });
441
442        let num_threads = 4;
443        let barrier = Arc::new(Barrier::new(num_threads));
444        let panics = Arc::new(AtomicUsize::new(0));
445
446        let handles: Vec<_> = (0..num_threads)
447            .map(|_| {
448                let mut iter = iter.clone();
449                let barrier = Arc::clone(&barrier);
450                let panics = Arc::clone(&panics);
451                thread::spawn(move || {
452                    barrier.wait();
453                    match std::panic::catch_unwind(AssertUnwindSafe(|| iter.next())) {
454                        // The driver panicked before producing anything, so a clean end is the
455                        // only non-panic outcome a consumer may observe.
456                        Ok(None) => {}
457                        Ok(Some(_)) => panic!("no item was produced before the driver panicked"),
458                        Err(panic) => {
459                            assert!(panic_message(&*panic).contains("multi consumer driver panic"));
460                            panics.fetch_add(1, Ordering::SeqCst);
461                        }
462                    }
463                })
464            })
465            .collect();
466
467        for handle in handles {
468            handle.join().expect("consumer thread panicked uncaught");
469        }
470
471        // The panic surfaces to exactly one consumer and is never swallowed by all of them.
472        assert_eq!(panics.load(Ordering::SeqCst), 1);
473    }
474
475    // Clean completion must return `None` with no spurious panic.
476    #[test]
477    fn test_block_on_stream_thread_safe_clean_completion_returns_none() {
478        let mut iter = CurrentThreadRuntime::new()
479            .block_on_stream_thread_safe(|_h| stream::iter(vec![1usize, 2, 3]).boxed());
480
481        assert_eq!(iter.next(), Some(1));
482        assert_eq!(iter.next(), Some(2));
483        assert_eq!(iter.next(), Some(3));
484        assert_eq!(iter.next(), None);
485        assert_eq!(iter.next(), None);
486    }
487
488    #[test]
489    fn test_block_on_stream_concurrent_clone_and_drive() {
490        let num_items = 50;
491        let num_threads = 3;
492
493        let iter = CurrentThreadRuntime::new().block_on_stream_thread_safe(|h| {
494            stream::unfold(0, move |state| {
495                let h = h.clone();
496                async move {
497                    if state < num_items {
498                        h.spawn_cpu(move || {
499                            thread::sleep(Duration::from_micros(10));
500                            state
501                        })
502                        .await;
503                        Some((state, state + 1))
504                    } else {
505                        None
506                    }
507                }
508            })
509        });
510
511        let collected = Arc::new(Mutex::new(Vec::new()));
512        let barrier = Arc::new(Barrier::new(num_threads));
513
514        let threads: Vec<_> = (0..num_threads)
515            .map(|thread_id| {
516                let iter = iter.clone();
517                let collected = Arc::clone(&collected);
518                let barrier = Arc::clone(&barrier);
519
520                thread::spawn(move || {
521                    barrier.wait();
522                    let mut local_items = Vec::new();
523
524                    for item in iter {
525                        local_items.push((thread_id, item));
526                        if local_items.len() >= 5 {
527                            break;
528                        }
529                    }
530
531                    collected.lock().extend(local_items);
532                })
533            })
534            .collect();
535
536        for thread in threads {
537            thread.join().unwrap();
538        }
539
540        let results = collected.lock();
541        let mut values: Vec<_> = results.iter().map(|(_, v)| *v).collect();
542        values.sort();
543        assert_eq!(values, (0..num_threads * 5).collect::<Vec<_>>());
544    }
545
546    #[test]
547    fn test_block_on_stream_async_work() {
548        let runtime = CurrentThreadRuntime::new();
549        let handle = runtime.handle();
550        let iter = runtime.block_on_stream({
551            stream::unfold((handle, 0), |(h, state)| async move {
552                if state < 10 {
553                    let value = h
554                        .spawn(async move { futures::future::ready(state * 2).await })
555                        .await;
556                    Some((value, (h, state + 1)))
557                } else {
558                    None
559                }
560            })
561        });
562
563        let results: Vec<_> = iter.collect();
564        assert_eq!(results, vec![0, 2, 4, 6, 8, 10, 12, 14, 16, 18]);
565    }
566
567    #[test]
568    fn test_block_on_stream_drop_receivers_early() {
569        let counter = Arc::new(AtomicUsize::new(0));
570        let c = Arc::clone(&counter);
571
572        let mut iter = CurrentThreadRuntime::new().block_on_stream({
573            stream::unfold(0, move |state| {
574                let c = Arc::clone(&c);
575                async move {
576                    (state < 100).then(|| {
577                        c.fetch_add(1, Ordering::SeqCst);
578                        (state, state + 1)
579                    })
580                }
581            })
582            .boxed()
583        });
584
585        assert_eq!(iter.next(), Some(0));
586        assert_eq!(iter.next(), Some(1));
587        assert_eq!(iter.next(), Some(2));
588
589        drop(iter);
590
591        let final_count = counter.load(Ordering::SeqCst);
592        assert!(
593            final_count < 100,
594            "Stream should stop when all receivers are dropped"
595        );
596    }
597
598    #[test]
599    fn test_block_on_stream_interleaved_access() {
600        let barrier = Arc::new(Barrier::new(2));
601        let iter = CurrentThreadRuntime::new()
602            .block_on_stream_thread_safe(|_h| stream::iter(0..20).boxed());
603
604        let iter1 = iter.clone();
605        let iter2 = iter;
606        let barrier1 = Arc::clone(&barrier);
607        let barrier2 = barrier;
608
609        let thread1 = thread::spawn(move || {
610            let mut iter = iter1;
611            let mut results = Vec::new();
612            barrier1.wait();
613
614            for _ in 0..5 {
615                if let Some(val) = iter.next() {
616                    results.push(val);
617                    thread::sleep(Duration::from_micros(50));
618                }
619            }
620            results
621        });
622
623        let thread2 = thread::spawn(move || {
624            let mut iter = iter2;
625            let mut results = Vec::new();
626            barrier2.wait();
627
628            for _ in 0..5 {
629                if let Some(val) = iter.next() {
630                    results.push(val);
631                    thread::sleep(Duration::from_micros(50));
632                }
633            }
634            results
635        });
636
637        let results1 = thread1.join().unwrap();
638        let results2 = thread2.join().unwrap();
639
640        let mut all_results = results1;
641        all_results.extend(results2);
642        all_results.sort();
643
644        assert_eq!(all_results, (0..10).collect::<Vec<_>>());
645
646        for i in 0..10 {
647            assert_eq!(all_results.iter().filter(|&&x| x == i).count(), 1);
648        }
649    }
650
651    #[test]
652    fn test_block_on_stream_stress_test() {
653        let num_threads = 10;
654        let num_items = 1000;
655
656        let iter = CurrentThreadRuntime::new()
657            .block_on_stream_thread_safe(|_h| stream::iter(0..num_items).boxed());
658
659        let received = Arc::new(Mutex::new(Vec::new()));
660        let barrier = Arc::new(Barrier::new(num_threads));
661
662        let threads: Vec<_> = (0..num_threads)
663            .map(|_| {
664                let iter = iter.clone();
665                let received = Arc::clone(&received);
666                let barrier = Arc::clone(&barrier);
667
668                thread::spawn(move || {
669                    barrier.wait();
670                    for val in iter {
671                        received.lock().push(val);
672                    }
673                })
674            })
675            .collect();
676
677        for thread in threads {
678            thread.join().unwrap();
679        }
680
681        let mut results = received.lock().clone();
682        results.sort();
683
684        assert_eq!(results.len(), num_items);
685        assert_eq!(results, (0..num_items).collect::<Vec<_>>());
686    }
687
688    #[test]
689    fn test_block_on_stream_prefetch_keeps_one_item_ahead() {
690        let runtime = CurrentThreadRuntime::new();
691        let produced = Arc::new(AtomicUsize::new(0));
692        let counter = Arc::clone(&produced);
693        let items = stream::iter(0..16).inspect(move |_| {
694            counter.fetch_add(1, Ordering::SeqCst);
695        });
696        let mut iter = runtime.block_on_stream_prefetch(items);
697        assert_eq!(iter.next(), Some(0));
698        runtime.block_on(async {
699            for _ in 0..64 {
700                runtime.handle().spawn(async {}).await;
701            }
702        });
703        assert_eq!(produced.load(Ordering::SeqCst), 2);
704        assert_eq!(iter.collect::<Vec<_>>(), (1..16).collect::<Vec<_>>());
705    }
706
707    #[test]
708    fn test_block_on_stream_prefetch_propagates_driver_panic() {
709        let runtime = CurrentThreadRuntime::new();
710        let items = stream::iter(0..2).map(|value| {
711            assert!(value != 1, "stream driver panic");
712            value
713        });
714        let mut iter = runtime.block_on_stream_prefetch(items);
715        assert_eq!(iter.next(), Some(0));
716        let panic = std::panic::catch_unwind(AssertUnwindSafe(|| iter.next()))
717            .expect_err("stream panic must propagate through iterator");
718        assert!(panic_message(panic.as_ref()).contains("stream driver panic"));
719    }
720}