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

Avoid trying to acquire lock twice when shutting down #3036

Merged

Conversation

vinistock
Copy link
Member

@vinistock vinistock commented Jan 9, 2025

Motivation

Closes #3039

We found another spot where nested code was trying to acquire the same mutex lock. Essentially, our shutdown was doing this.

@global_state.synchronize do
  # Joining this thread will also try to acquire the same lock, which leads to a deadlock
  # We need to synchronize to prevent mangled output being written to the pipes
  @outgoing_queue.join
end

Implementation

I think there's no real point in joining the worker and outgoing threads. The server is already being shutdown anyway, so why would we try to return more responses back to the editor? We can just terminate the threads and prevent a deadlock from happening.

Copy link
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@vinistock vinistock added server This pull request should be included in the server gem's release notes bugfix This PR will fix an existing bug labels Jan 9, 2025 — with Graphite App
@vinistock vinistock marked this pull request as ready for review January 9, 2025 21:55
@vinistock vinistock requested a review from a team as a code owner January 9, 2025 21:55
@vinistock vinistock merged commit a49104e into main Jan 10, 2025
43 of 44 checks passed
@vinistock vinistock deleted the 01-09-avoid_trying_to_acquire_lock_twice_when_shutting_down branch January 10, 2025 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This PR will fix an existing bug server This pull request should be included in the server gem's release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Connection to server got closed" error after initiating a rebase
3 participants