Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix race condition that could lose a transfer completion wakup #92

Merged
merged 1 commit into from
Nov 20, 2024

Conversation

kevinmehall
Copy link
Owner

@kevinmehall kevinmehall commented Nov 16, 2024

If poll_completion_generic runs between notify_completion's waker.take() and state.swap(STATE_COMPLETED, ...), it could see the transfer as pending and register its waker, but that waker would never be called.

This adds an Arc because once the transfer is set to STATE_COMPLETED, the other thread might free it, so we need to ensure the AtomicWaker stays alive while we use it. That's what the take() was intended to work around, but reading the waker before writing the status introduces the race.

Fixes #89

If `poll_completion_generic` runs between `notify_completion`'s
`waker.take()` and `state.swap(STATE_COMPLETED, ...)`, it could see the
transfer as pending and register its waker, but that waker would never
be called.

This adds an Arc because once the transfer is set to `STATE_COMPLETED`,
the other thread might free it, so we need to ensure the AtomicWaker
stays alive while we use it. That's what the `take()` was intended
to work around, but reading the waker before writing the status
introduces the race.
@kevinmehall kevinmehall merged commit 4bdc50b into v0.1 Nov 20, 2024
16 checks passed
@kevinmehall kevinmehall deleted the waker-race branch November 20, 2024 05:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant