Skip to content

Commit 7a23e16

Browse files
committed
fix very slow poll_writable()
1 parent 8c3c3bd commit 7a23e16

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/reactor.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,9 @@ impl Source {
461461
panic::catch_unwind(|| w.wake()).ok();
462462
}
463463
state[dir].waker = Some(cx.waker().clone());
464-
state[dir].ticks = Some((Reactor::get().ticker(), state[dir].tick));
464+
if state[dir].ticks.is_none() {
465+
state[dir].ticks = Some((Reactor::get().ticker(), state[dir].tick));
466+
}
465467

466468
// Update interest in this I/O handle.
467469
if was_empty {

tests/async.rs

+20
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::thread;
88
use std::time::Duration;
99

1010
use async_io::{Async, Timer};
11+
use futures_lite::future::poll_fn;
1112
use futures_lite::{future, prelude::*};
1213
#[cfg(unix)]
1314
use tempfile::tempdir;
@@ -155,6 +156,25 @@ fn udp_send_recv() -> io::Result<()> {
155156
})
156157
}
157158

159+
160+
#[test]
161+
fn test_poll_writable_iterations() -> io::Result<()> {
162+
future::block_on(async {
163+
let socket = Async::<UdpSocket>::bind(([127, 0, 0, 1], 0))?;
164+
165+
let mut attempts = 0;
166+
167+
poll_fn(|cx| {
168+
attempts += 1;
169+
socket.poll_writable(cx)
170+
}).await?;
171+
172+
assert!(attempts < 5);
173+
174+
Ok(())
175+
})
176+
}
177+
158178
#[cfg(unix)]
159179
#[test]
160180
fn udp_connect() -> io::Result<()> {

0 commit comments

Comments
 (0)