From 3ac36879e0ef41e1cdfce38f61607dfbf75d5cd6 Mon Sep 17 00:00:00 2001 From: Reilly Wood <26268125+rgwood@users.noreply.github.com> Date: Fri, 2 Dec 2022 08:00:56 -0800 Subject: [PATCH] Handle `ctrl-c` in `RawStream` iterator (#7314) Fixes #7246 and #1898. Darren noticed that `open /dev/random` could not be interrupted by `ctrl+c`. Thankfully the solution was very simple; it looks like we just forgot to check `ctrlc` in the `impl Iterator for RawStream`! To reproduce this, just run `open /dev/random` and then cancel it with `ctrl+c`. --- crates/nu-protocol/src/value/stream.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/nu-protocol/src/value/stream.rs b/crates/nu-protocol/src/value/stream.rs index 47ccb6b44..af0a6dd76 100644 --- a/crates/nu-protocol/src/value/stream.rs +++ b/crates/nu-protocol/src/value/stream.rs @@ -77,6 +77,12 @@ impl Iterator for RawStream { type Item = Result; fn next(&mut self) -> Option { + if let Some(ctrlc) = &self.ctrlc { + if ctrlc.load(Ordering::SeqCst) { + return None; + } + } + // If we know we're already binary, just output that if self.is_binary { match self.stream.next() {