Skip to content

Commit 71e40c0

Browse files
authored
Merge pull request #2 from kamalmarhubi/retry-interrupted
mio: Retry poll if interrupted
2 parents 113646f + 4bc1ec3 commit 71e40c0

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

mio/src/lib.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ extern crate mio;
22
extern crate futures;
33

44
use std::collections::HashMap;
5-
use std::io::{self, Read, Write};
5+
use std::io::{self, ErrorKind, Read, Write};
66
use std::net::SocketAddr;
77
use std::panic;
88
use std::slice;
@@ -231,7 +231,20 @@ impl Loop {
231231

232232
fn _await(&mut self, done: &mut FnMut() -> bool) {
233233
while !done() {
234-
let amt = self.io.poll(None).unwrap();
234+
let amt;
235+
// On Linux, Poll::poll is epoll_wait, which may return EINTR if a
236+
// ptracer attaches. This retry loop prevents crashing when
237+
// attaching strace, or similar.
238+
loop {
239+
match self.io.poll(None) {
240+
Ok(a) => {
241+
amt = a;
242+
break;
243+
}
244+
Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
245+
err@Err(_) => { err.unwrap(); },
246+
}
247+
}
235248

236249
for i in 0..amt {
237250
let event = self.io.events().get(i).unwrap();

0 commit comments

Comments
 (0)