Skip to content

Fix Weak Increment Race Condition#60

Merged
notgull merged 4 commits into
smol-rs:masterfrom
jayhf:jf/fix-weak-race-condition
Jun 4, 2023
Merged

Fix Weak Increment Race Condition#60
notgull merged 4 commits into
smol-rs:masterfrom
jayhf:jf/fix-weak-race-condition

Conversation

@jayhf

@jayhf jayhf commented May 22, 2023

Copy link
Copy Markdown
Contributor

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

@notgull notgull left a comment

Copy link
Copy Markdown
Contributor

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

jayhf commented May 29, 2023

Copy link
Copy Markdown
Contributor Author

@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

@notgull notgull left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread src/lib.rs
} else {
Some(Sender {
match self.channel.sender_count.fetch_update(
Ordering::Relaxed,

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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

@notgull notgull left a comment

Copy link
Copy Markdown
Contributor

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