Skip to content

fix(semaphore): Fix semaphore reopens after forget#8021

Merged
Darksonn merged 2 commits intotokio-rs:masterfrom
dentiny:hjiang/fix-semaphore-reopen-on-forget
Apr 8, 2026
Merged

fix(semaphore): Fix semaphore reopens after forget#8021
Darksonn merged 2 commits intotokio-rs:masterfrom
dentiny:hjiang/fix-semaphore-reopen-on-forget

Conversation

@dentiny
Copy link
Copy Markdown
Contributor

@dentiny dentiny commented Apr 7, 2026

Motivation

Closes #8020

Current forget_semaphores doesn't consider LSB (Least Significant Bit), which is used to store semaphore open or closed, which leads to a weird behavior that semaphore reopens.

Solution

This PR sets the "closed" bit on forget_semaphores, another alternative I considered is to return error on close, but that seems to be an interface change which I'd like to avoid.

@github-actions github-actions Bot added the R-loom-sync Run loom sync tests on this PR label Apr 7, 2026
@Darksonn Darksonn added A-tokio Area: The main tokio crate M-sync Module: tokio/sync labels Apr 8, 2026
@Darksonn
Copy link
Copy Markdown
Member

Darksonn commented Apr 8, 2026

Oh I didn't see you submitted a PR for the bug, so now we have two fixes: #8022. I'll take your fix, but do you mind copying over the tests I wrote, as they are more exhaustive.

@dentiny
Copy link
Copy Markdown
Contributor Author

dentiny commented Apr 8, 2026

Oh I didn't see you submitted a PR for the bug, so now we have two fixes: #8022. I'll take your fix, but do you mind copying over the tests I wrote, as they are more exhaustive.

Yeah sure absolutely! Thank you so much for the kindness!

Copy link
Copy Markdown
Member

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

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

Thanks!

@Darksonn Darksonn enabled auto-merge (squash) April 8, 2026 07:43
@Darksonn Darksonn merged commit 3ea11e2 into tokio-rs:master Apr 8, 2026
90 checks passed
adriandomc added a commit to adriandomc/coontext that referenced this pull request Apr 8, 2026
Dependabot PR #5 (closed as a side effect of the earlier force-push).
Patch bump within the 1.x line — no API changes. Upstream release
notes call out:

- sync: fix semaphore reopens after forget (tokio-rs/tokio#8021)
- net: surface errors from SO_ERROR on recv for UDP sockets on Linux
  (tokio-rs/tokio#8001)

Neither affects Coontext directly (we don't use semaphores or UDP), but
the patch is free. Also tightens the manifest version floor from 1.40
to 1.51 to document the actual minimum we now rely on.

Verified locally on macOS:
- cargo fmt --all -- --check  clean
- cargo clippy --all-targets -- -D warnings  clean
- cargo test --lib  104 passed, 0 failed

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Dicklesworthstone added a commit to Dicklesworthstone/meta_skill that referenced this pull request Apr 10, 2026
tokio 1.51.1 includes:
- sync: fix semaphore reopens after forget (tokio-rs/tokio#8021)
- net: surface errors from SO_ERROR on recv for UDP sockets on Linux
- rt: do not leak fd when cancelling io_uring open operation
- runtime: steal tasks from LIFO slot, stabilize LocalRuntime

semver 1.0.28 is documentation-only; picked up for currency.

Applied independently (not via Dependabot merge) per contribution policy.
Closes #81, #82.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-tokio Area: The main tokio crate M-sync Module: tokio/sync R-loom-sync Run loom sync tests on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Forgetting permits on a closed semaphore reopens it

2 participants