Skip to content

Commit

Permalink
fix very slow poll_writable()
Browse files Browse the repository at this point in the history
  • Loading branch information
davibe committed Oct 2, 2023
1 parent 8c3c3bd commit 37db00c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/reactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,9 @@ impl Source {
panic::catch_unwind(|| w.wake()).ok();
}
state[dir].waker = Some(cx.waker().clone());
state[dir].ticks = Some((Reactor::get().ticker(), state[dir].tick));
if state[dir].ticks.is_none() {
state[dir].ticks = Some((Reactor::get().ticker(), state[dir].tick));
}

// Update interest in this I/O handle.
if was_empty {
Expand Down
20 changes: 20 additions & 0 deletions tests/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::thread;
use std::time::Duration;

use async_io::{Async, Timer};
use futures_lite::future::poll_fn;
use futures_lite::{future, prelude::*};
#[cfg(unix)]
use tempfile::tempdir;
Expand Down Expand Up @@ -155,6 +156,25 @@ fn udp_send_recv() -> io::Result<()> {
})
}

#[test]
fn test_poll_writable_iterations() -> io::Result<()> {
future::block_on(async {
let socket = Async::<UdpSocket>::bind(([127, 0, 0, 1], 0))?;

let mut attempts = 0;

poll_fn(|cx| {
attempts += 1;
socket.poll_writable(cx)
})
.await?;

assert!(attempts < 5);

Ok(())
})
}

#[cfg(unix)]
#[test]
fn udp_connect() -> io::Result<()> {
Expand Down

0 comments on commit 37db00c

Please sign in to comment.