From 1a9507af4710ec51b81a2ebc819e8ecee9b1e4ce Mon Sep 17 00:00:00 2001 From: Cameron Bytheway Date: Thu, 2 Jan 2025 16:08:34 -0700 Subject: [PATCH] fix(s2n-quic-dc): handle spurious TCP acceptor worker wakeups --- dc/s2n-quic-dc/src/stream/server/tokio/tcp/manager.rs | 7 +++++++ .../src/stream/server/tokio/tcp/manager/tests.rs | 5 ++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/dc/s2n-quic-dc/src/stream/server/tokio/tcp/manager.rs b/dc/s2n-quic-dc/src/stream/server/tokio/tcp/manager.rs index 18f3ad604..c2381a030 100644 --- a/dc/s2n-quic-dc/src/stream/server/tokio/tcp/manager.rs +++ b/dc/s2n-quic-dc/src/stream/server/tokio/tcp/manager.rs @@ -254,6 +254,13 @@ where let mut cf = ControlFlow::Continue(()); let entry = &mut self.workers[idx]; + + // Only poll the worker if it's active. We can end up here if we've pruned a worker right before + // the tokio runtime notifies us the stream is ready. + if !entry.worker.is_active() { + return cf; + } + let mut task_cx = task::Context::from_waker(&entry.waker); let Poll::Ready(res) = entry.worker.poll(&mut task_cx, cx, publisher, clock) else { debug_assert!(entry.worker.is_active()); diff --git a/dc/s2n-quic-dc/src/stream/server/tokio/tcp/manager/tests.rs b/dc/s2n-quic-dc/src/stream/server/tokio/tcp/manager/tests.rs index 04bb79027..b822d0355 100644 --- a/dc/s2n-quic-dc/src/stream/server/tokio/tcp/manager/tests.rs +++ b/dc/s2n-quic-dc/src/stream/server/tokio/tcp/manager/tests.rs @@ -171,9 +171,8 @@ impl Harness { let Entry { worker, waker, .. } = &mut self.manager.inner.workers[idx]; let is_active = worker.is_active(); - if is_active { - waker.wake_by_ref(); - } + // wake the worker even if it's not active so we can test more paths + waker.wake_by_ref(); is_active }