Skip to content

Commit

Permalink
fix: missing waker.wake
Browse files Browse the repository at this point in the history
My analysis of the problem is that using the current `Reactor::ticker`
value in `ticks` is not always correct. It is my understanding that when
placing a ticker value into `Direction::ticks` there is a guarantee that
the waker.wake call has completed and the associated task has been run.
The problem is the increment of the ticker value is in `ReactorLock::react`
is typically running on a different CPU thread than the
`Source::poll_ready` (called by `poll_readable`, `poll_writeable`), which
is saving the ticker value in ticks:

  state[dir].ticks = Some((Reactor::get().ticker(), state[dir].tick));

Because the increment and use of ticker value are on different threads
the required guarantee can not be full filled and I'm proposing the
following fix in this PR, which only uses the a current `state[dir].tick`
and not the ticker value:

  state[dir].ticks = Some((state[dir].tick, 0)

fix smol-rs#78
  • Loading branch information
winksaville committed May 6, 2022
1 parent 153c732 commit 71cd97d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/reactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ 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));
state[dir].ticks = Some((state[dir].tick, 0));

// Update interest in this I/O handle.
if was_empty {
Expand Down

0 comments on commit 71cd97d

Please sign in to comment.