Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions crates/amalthea/src/sys/unix/stream_capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,28 @@ impl StreamCapture {
let stderr_poll = nix::poll::PollFd::new(stderr_fd, nix::poll::PollFlags::POLLIN);
let mut poll_fds = [stdout_poll, stderr_poll];

log::info!("Starting thread for stdout/stderr capture");

loop {
// Wait for data to be available on either stdout or stderr. This
// blocks until data is available, the streams are interrupted, or
// the timeout occurs.
let count = match nix::poll::poll(&mut poll_fds, 1000) {
Ok(c) => c,
Err(e) => {
// If the poll was interrupted, stop listening.
if (e as i32) == nix::errno::Errno::EINTR as i32 {
break;
Err(err) => {
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/poll.html
match err {
// If the poll was interrupted, silently continue
nix::errno::Errno::EINTR => continue,

// Internal allocation has failed, but a retry might succeed
nix::errno::Errno::EAGAIN => continue,

_ => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The remaining error documented in https://pubs.opengroup.org/onlinepubs/9699919799/functions/poll.html represents an unexpected state, so quitting the thread is likely appropriate.

log::error!("Error polling for stream data: {err:?}");
break;
},
}
warn!("Error polling for stream data: {}", e);
continue;
},
};

Expand All @@ -86,7 +95,7 @@ impl StreamCapture {
} else if fd == stderr_fd {
Stream::Stderr
} else {
warn!("Unknown stream fd: {}", fd);
log::warn!("Unknown stream fd: {}", fd);
continue;
};

Expand All @@ -95,7 +104,8 @@ impl StreamCapture {
}
}
}
warn!("Stream capture thread exiting after interrupt");

log::warn!("Stream capture thread exiting after interrupt");
Ok(())
}

Expand Down
Loading