8000 fix(voice): prevent gateway lock order deadlock by kota113 · Pull Request #588 · disgoorg/disgo · GitHub
[go: up one dir, main page]

Skip to content

fix(voice): prevent gateway lock order deadlock - #588

Merged
topi314 merged 1 commit into
disgoorg:masterfrom
kota113:fix/lock-mutex-in-order
Oct 23, 2026
Merged

topi314 merged 1 commit into
disgoorg:masterfrom
kota113:fix/lock-mutex-in-order

Conversation

@kota113
@kota113 kota113 commented Aug 11, 2026 •
Copy link
Copy Markdown
Contributor

Summary

  • Use a consistent mutex acquisition order for voice gateway connection and status state.
  • Avoid holding the status mutex while waiting for the connection mutex.
  • Add regression coverage ensuring status reads remain responsive while a send waits for the connection lock.

Problem

gatewayImpl.Send held statusMu and then attempted to acquire connMu. Other gateway paths, including connection opening and closing, acquire connMu before statusMu.

When these paths ran concurrently, they could form a lock-order cycle: a send waited for the connection mutex while holding the status mutex, and a connection lifecycle operation waited for the status mutex while holding the connection mutex. This could permanently block voice gateway operations.

Changes

  • Check whether the gateway is ready without retaining statusMu while waiting for connMu.
  • Acquire connMu before rechecking gateway readiness under statusMu, matching the order used by connection lifecycle paths.
  • Split the internal send helpers into locking and lock-held variants so all writes remain serialized without recursively acquiring connMu.
  • Add TestSendDoesNotBlockStatusWhileWaitingForConnection to cover the lock-order regression.

Testing

  • go test -race ./voice
  • go test ./...
  • go vet ./...

@sealbro
sealbro commented Oct 23, 2026
Copy link
Copy Markdown
Contributor

Hi! I hit this deadlock in production: a DAVE prepare-epoch sent while the bot leaves voice hangs Send and Close. This PR fixes it in our reproduction. Right now I work around it with a wrapper, and we'd like to remove that. 🙏

@topi314
topi314 force-pushed the fix/lock-mutex-in-order branch from 4502802 to 4e3545b Compare October 23, 2026 18:51
@topi314
topi314 merged commit 5bf95eb into disgoorg:master Oct 23, 2026
4 checks passed
@topi314
topi314 commented Oct 23, 2026
Copy link
Copy Markdown
Member

thanks

@kota113
kota113 commented Oct 23, 2026 •
Copy link
Copy Markdown
Contributor Author

thanks for your attention!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants

0