From e7fc698f244b11ed1425eea2a39d667cfcb1388d Mon Sep 17 00:00:00 2001 From: Jonathan Date: Sun, 26 Feb 2023 17:39:19 +0200 Subject: [PATCH] Do not panic on poll() errors, and ignore EINTR (#762) --- src/event/source/unix/tty.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/event/source/unix/tty.rs b/src/event/source/unix/tty.rs index b9eb43604..ca77e3d89 100644 --- a/src/event/source/unix/tty.rs +++ b/src/event/source/unix/tty.rs @@ -131,8 +131,20 @@ impl EventSource for UnixInternalEventSource { return Ok(Some(event)); } match poll(&mut fds, timeout.leftover()) { - Err(filedescriptor::Error::Io(e)) => return Err(e), - res => res.expect("polling tty"), + Err(filedescriptor::Error::Poll(e)) | Err(filedescriptor::Error::Io(e)) => { + match e.kind() { + // retry on EINTR + io::ErrorKind::Interrupted => continue, + _ => return Err(e), + } + } + Err(e) => { + return Err(std::io::Error::new( + std::io::ErrorKind::Other, + format!("got unexpected error while polling: {:?}", e), + )) + } + Ok(_) => (), }; if fds[0].revents & POLLIN != 0 { loop {