Skip to content

Fix OAuth local server shutdown deadlock and add timeout#66

Merged
telegrapher merged 1 commit into
mainfrom
fix/oauth-shutdown-deadlock
Feb 26, 2026
Merged

Fix OAuth local server shutdown deadlock and add timeout#66
telegrapher merged 1 commit into
mainfrom
fix/oauth-shutdown-deadlock

Conversation

@telegrapher

Copy link
Copy Markdown
Collaborator

Summary

  • Fix deadlock on shutdown. The local OAuth server uses unbuffered channels (ims-go/login/server.go:91-92) to send results from HTTP handlers to the main goroutine. If the 5-minute user timeout fires and a late browser callback writes to the channel with nobody reading, a circular dependency forms: Shutdown() waits for the handler to return, the handler blocks on the channel write. Draining both channels before Shutdown() breaks the deadlock.

  • Add 10-second timeout to Shutdown(). The original code used context.Background() with no deadline, which could wait indefinitely. Now uses context.WithTimeout as a safety net.

  • Add documentation. docs/oauth-shutdown-deadlock.md explains the deadlock scenario step-by-step with file and line references.

The local OAuth server uses unbuffered channels for communicating results
between HTTP handlers and the main goroutine. If the 5-minute user timeout
fires and a handler tries to write to the channel after nobody is reading,
a deadlock occurs: Shutdown() waits for the handler, the handler waits for
a channel reader.

Drain both channels before calling Shutdown() to break the deadlock, and
add a 10-second timeout to Shutdown() as a safety net.
@telegrapher
telegrapher merged commit df07a5c into main Feb 26, 2026
5 checks passed
@telegrapher
telegrapher deleted the fix/oauth-shutdown-deadlock branch February 28, 2026 13: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.

2 participants