Fix race condition related bugs (#243)

* Fix races.

This mostly pulls in changes from rust-lang-nursery/futures-rs#881, but
also updates Registration to be a bit more obvious as to what is going
on.

* Reduce spurious wakeups caused by Reactor

This patch adds an ABA guard on token values before registering them
with Mio. This allows catching token reuse and avoid the notification.

This is needed for OS X as the notification is used to determine that a
TCP connect has completed. A spurious notification can potentially cause
write failures.
This commit is contained in:
Carl Lerche
2018-03-22 09:57:40 -07:00
committed by GitHub
parent 8786741ba9
commit 08c21e7bac
9 changed files with 409 additions and 183 deletions
+2 -1
View File
@@ -936,9 +936,10 @@ impl Future for Shutdown {
type Error = ();
fn poll(&mut self) -> Poll<(), ()> {
use futures::task;
trace!("Shutdown::poll");
self.inner().shutdown_task.task1.register();
self.inner().shutdown_task.task1.register_task(task::current());
if 0 != self.inner().num_workers.load(Acquire) {
return Ok(Async::NotReady);
+2 -2
View File
@@ -222,13 +222,13 @@ impl Task {
let actual = self.inner().state.compare_and_swap(
Idle.into(),
Scheduled.into(),
Relaxed).into();
AcqRel).into();
match actual {
Idle => return true,
Running => {
let actual = self.inner().state.compare_and_swap(
Running.into(), Notified.into(), Relaxed).into();
Running.into(), Notified.into(), AcqRel).into();
match actual {
Idle => continue,