Skip to content

fix(server): eliminate nested mutex acquisition in SSH tunnel handler#650

Closed
persimmon16 wants to merge 1 commit intoNVIDIA:mainfrom
persimmon16:fix/ssh-mutex-lock-ordering
Closed

fix(server): eliminate nested mutex acquisition in SSH tunnel handler#650
persimmon16 wants to merge 1 commit intoNVIDIA:mainfrom
persimmon16:fix/ssh-mutex-lock-ordering

Conversation

@persimmon16
Copy link
Copy Markdown

Summary

  • Restructures the per-sandbox SSH connection limit check to release ssh_connections_by_sandbox before acquiring ssh_connections_by_token for rollback
  • Eliminates a nested lock pattern (sandbox -> token) that risked deadlock if any other code path locked in reverse order

Related Issue

Production readiness audit finding (P3): SSH connection dual-Mutex lock ordering could cause deadlocks.

Changes

  • crates/openshell-server/src/ssh_tunnel.rs: Split the per-sandbox limit check into two phases — check-and-release, then rollback separately

Testing

  • cargo check -p openshell-server passes
  • cargo clippy clean (only pre-existing warnings)
  • Audited decrement_connection_count helper — already acquires each mutex independently

Checklist

  • Conventional commit format
  • No secrets committed
  • Scoped to the issue at hand

Restructure the per-sandbox connection limit check to release
ssh_connections_by_sandbox before acquiring ssh_connections_by_token
for the rollback. The previous code held both mutexes simultaneously,
creating a potential deadlock if any other code path acquired them in
the opposite order.
@persimmon16 persimmon16 requested a review from a team as a code owner March 28, 2026 19:53
@github-actions
Copy link
Copy Markdown

Thank you for your submission! We ask that you sign our Developer Certificate of Origin before we can accept your contribution. You can sign the DCO by adding a comment below using this text:


I have read the DCO document and I hereby sign the DCO.


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the DCO Assistant Lite bot.

@github-actions
Copy link
Copy Markdown

Thank you for your interest in contributing to OpenShell, @persimmon16.

This project uses a vouch system for first-time contributors. Before submitting a pull request, you need to be vouched by a maintainer.

To get vouched:

  1. Open a Vouch Request discussion.
  2. Describe what you want to change and why.
  3. Write in your own words — do not have an AI generate the request.
  4. A maintainer will comment /vouch if approved.
  5. Once vouched, open a new PR (preferred) or reopen this one after a few minutes.

See CONTRIBUTING.md for details.

@github-actions github-actions bot closed this Mar 28, 2026
@persimmon16 persimmon16 deleted the fix/ssh-mutex-lock-ordering branch March 28, 2026 19:56
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