fix: race race in attaching to existing sessions#366
Merged
ethanpailes merged 2 commits intomasterfrom May 7, 2026
Merged
Conversation
This patch migrates from stdlib mutexes to parking lot mutexes. This probably provides some small perf win, but the main reason I want it is for the arc_lock method that I'm going to need in order to fix a race condition in how we handle attaches.
Contributor
Author
|
In practice this should only happen during a suspend or something like that. That's how I encountered the issue. |
This patch fixes a race condition that could happen when two different procs raced to attach to a given session. Since we release the session lock breifly as part of the attach handshake, we were leaving a window open in which two racing attaches could trample on one another. The regression test in this patch shows the issue in detail. To fix the issue, I had select_shell_desc start returning the lock guard for the session so that there was no gap in which the lock was released. In order to do that, I needed to switch to use parking_lot mutexes, since it is impossible to return the lock guard for an Arc<Mutex<T>> using the stdlib types.
06fa128 to
8021f79
Compare
Contributor
Author
|
I split this up into one commit for the Mutex migration and one for the actual fix to make it easier to review in isolation. |
3 tasks
maxhbooth
approved these changes
May 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue Link
n/a I just noticed this when I logged on this morning
AI Policy Ack
Ack
This PR was:
I wrote the fix, gemini wrote the test and helped with diagnosis.
Description