Skip to content

Commit 674475d

Browse files
authored
Continue listening when poll() is interrupted (#941)
1 parent aa55e36 commit 674475d

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

crates/amalthea/src/sys/unix/stream_capture.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,28 @@ impl StreamCapture {
4747
let stderr_poll = nix::poll::PollFd::new(stderr_fd, nix::poll::PollFlags::POLLIN);
4848
let mut poll_fds = [stdout_poll, stderr_poll];
4949

50+
log::info!("Starting thread for stdout/stderr capture");
51+
5052
loop {
5153
// Wait for data to be available on either stdout or stderr. This
5254
// blocks until data is available, the streams are interrupted, or
5355
// the timeout occurs.
5456
let count = match nix::poll::poll(&mut poll_fds, 1000) {
5557
Ok(c) => c,
56-
Err(e) => {
57-
// If the poll was interrupted, stop listening.
58-
if (e as i32) == nix::errno::Errno::EINTR as i32 {
59-
break;
58+
Err(err) => {
59+
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/poll.html
60+
match err {
61+
// If the poll was interrupted, silently continue
62+
nix::errno::Errno::EINTR => continue,
63+
64+
// Internal allocation has failed, but a retry might succeed
65+
nix::errno::Errno::EAGAIN => continue,
66+
67+
_ => {
68+
log::error!("Error polling for stream data: {err:?}");
69+
break;
70+
},
6071
}
61-
warn!("Error polling for stream data: {}", e);
62-
continue;
6372
},
6473
};
6574

@@ -86,7 +95,7 @@ impl StreamCapture {
8695
} else if fd == stderr_fd {
8796
Stream::Stderr
8897
} else {
89-
warn!("Unknown stream fd: {}", fd);
98+
log::warn!("Unknown stream fd: {}", fd);
9099
continue;
91100
};
92101

@@ -95,7 +104,8 @@ impl StreamCapture {
95104
}
96105
}
97106
}
98-
warn!("Stream capture thread exiting after interrupt");
107+
108+
log::warn!("Stream capture thread exiting after interrupt");
99109
Ok(())
100110
}
101111

0 commit comments

Comments
 (0)