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 Weak Increment Race Condition #60

Merged
merged 4 commits into from
Jun 4, 2023

Conversation

jayhf
Copy link
Contributor

@jayhf jayhf commented May 22, 2023

The sender/receiver counts are currently read and updated separately, which means there's a possible race condition where two attempt to get upgraded from different threads at the same time. This PR switches to using fetch_update to avoid this issue

Copy link
Member

@notgull notgull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bump the MSRV to 1.45, since fetch_update wasn't stable until then.

Also run cargo fmt --all to keep the code looking nice.

@jayhf
Copy link
Contributor Author

jayhf commented May 29, 2023

@notgull CI is passing now, except the MSRV check is failing, seemingly due a flaky failure to download the Cargo registry. Could you please rerun that action? I don't have permission

@jayhf jayhf requested a review from notgull May 29, 2023 14:24
Copy link
Member

@notgull notgull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me aside from a minor ordering change.

} else {
Some(Sender {
match self.channel.sender_count.fetch_update(
Ordering::Relaxed,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The set ordering here should be Release.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you elaborate on what this would guard against? I'm not seeing any other writes that this would need to be ordered with, but I'm probably just missing something

@jayhf jayhf requested a review from notgull June 4, 2023 12:45
Copy link
Member

@notgull notgull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@notgull notgull merged commit 14ba707 into smol-rs:master Jun 4, 2023
@notgull notgull mentioned this pull request Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants