Repository navigation
Conversation
drcaramelsyrup
left a comment
There was a problem hiding this comment.
Thanks for the fix here. I think it looks good pending one minor unnecessary bit.
|
@drcaramelsyrup Thanks for pointing that out! You're right—creating the Notified future is sufficient for notify_waiters(), so I've removed both lines and squashed the change into the original commit. |
|
@cuishuang Thanks again, we saw a minor detail in internal review. We can apply it as another commit on top if desired or let you revise. |
Signed-off-by: cuishuang <imcusg@gmail.com>
@drcaramelsyrup Thanks for catching both of these! I updated poll() to return the inner future directly and kept only the fired flag check after creating Notified. I confirmed the future shrank from 128 to 104 bytes locally. All 18 tests and Clippy pass, and I’ve pushed the revision as a single commit. |
TimerStub::poll read the fired flag and only then called Notify::notified(). Timer::fire wakes with notify_waiters, which only reaches a Notified that already exists, so a timer firing between the two steps woke nobody and the stub waited forever. Every lorica_timeout::timeout and sleep goes through it: a lost wakeup left a connect, handshake or HTTP/2 idle timeout unenforced. Port of upstream PR cloudflare/pingora#983 (head 12fc297b), open and not yet merged: the stub creates the Notified first, then reads the flag, and its test fires the timer through a hook before the waiter exists. That test fails on the old order. A separate probe firing the timer on another thread during the stub's first poll lost 20 wakeups in 200,000 races on the old order and none in 1,000,000 on the new one. Recorded as a divergence in FORK.md until the PR is merged.
Summary
TimerStub::poll()could miss a timer notification ifTimer::fire()ran between the fired flag check and creation of theNotifiedfuture.notify_waiters()does not retain a permit for futures created after the notification, so the timer could remain pending indefinitely.Create the
Notifiedfuture before checking the fired flag once. A fire before creation is observed via the flag. A fire after creation reaches the future even before its first poll. Return the inner future directly sofast_timeoutboxes a smaller future (104 bytes versus 128 bytes for the previous revision on the local toolchain).The regression test fires the timer before creating the
Notifiedfuture and verifies the wait completes.Validation
cargo test -p pingora-timeout(18 passed)cargo clippy -p pingora-timeout --all-targets -- -D warningscargo fmt -p pingora-timeout -- --check