Skip to content

fix/conn: avoid deadlock in re-entrant protocol error logging - #99

Merged
keegancsmith merged 1 commit into
masterfrom
k/fix-reentrant-logger-deadlock
Jul 31, 2026
Merged

fix/conn: avoid deadlock in re-entrant protocol error logging#99
keegancsmith merged 1 commit into
masterfrom
k/fix-reentrant-logger-deadlock

Conversation

@keegancsmith

Copy link
Copy Markdown
Member

A custom logger can call back into the same JSON-RPC connection—for example, to forward logs to the peer. When malformed input caused a protocol error, connection shutdown previously invoked that logger while holding the connection mutex. If the logger called `Notify`, it attempted to reacquire the mutex and deadlocked before shutdown could complete.

This marks the connection closed and releases its mutex before invoking the logger. Shutdown and transport cleanup complete first, so a re-entrant call now returns `ErrClosed` rather than blocking. A regression test reproduces the reported setup and verifies that both the logger and disconnect notification complete.

Fixes #98.

Protocol errors invoke the configured logger while the connection is shutting down. Calling user code under the connection mutex meant a logger that sends over the same connection could never observe closure and instead deadlocked. Complete teardown before logging so re-entrant calls return ErrClosed.

Amp-Thread-ID: https://ampcode.com/threads/T-019fb774-aef7-75df-8eb3-8888d6835754
Co-authored-by: Amp <amp@ampcode.com>
@keegancsmith
keegancsmith merged commit c3088e5 into master Jul 31, 2026
1 of 2 checks passed
@keegancsmith
keegancsmith deleted the k/fix-reentrant-logger-deadlock branch July 31, 2026 11:47
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.

Potential Deadlock when jsonrpc2.Logger sends messages over same jsonrpc2.Conn

3 participants