Skip to content

Fix ConnectionClosedException propagating uncaught to Netty event loop#454

Closed
lucassaldanha wants to merge 22 commits intolibp2p:masterfrom
lucassaldanha:fix-log
Closed

Fix ConnectionClosedException propagating uncaught to Netty event loop#454
lucassaldanha wants to merge 22 commits intolibp2p:masterfrom
lucassaldanha:fix-log

Conversation

@lucassaldanha
Copy link
Copy Markdown
Collaborator

@lucassaldanha lucassaldanha commented Apr 20, 2026

Summary

  • In Netty 4.2.x, writing to a locally-disconnected stream caused a ConnectionClosedException to escape MuxChannel.doWrite() uncaught, surfacing as spurious PLEASE FIX OR REPORT noise in Teku logs.
  • The original throw+catch pattern caught the exception locally, but the subsequent buf.remove(cause) call — sitting outside any try/catch — can propagate exceptions back through promise-listener callbacks in certain Netty versions.
  • Fix: move the localDisconnected check outside the try/catch and wrap buf.remove(cause) defensively so nothing can escape doWrite(). Pending write promises are still properly failed with ConnectionClosedException.

Test plan

  • Added regression test in MuxHandlerAbstractTest that sets localDisconnected = true while the channel is still active (simulating the window between flag assignment and deactivate() in doDisconnect()), calls writeAndFlush, and asserts the write future is failed with ConnectionClosedException — no uncaught exception
  • Run ./gradlew :libp2p:test --tests "io.libp2p.mux.*" — all 34 mux tests pass

ianopolous and others added 22 commits April 11, 2025 12:26
Quic secure transport implementation

---------

Co-authored-by: Anton Nashatyrev <anton.nashatyrev@gmail.com>
* Relay local/remote multiaddress retrieval to Transport implementations to get rid of subclass checks
* chore: add or force update .github/workflows/stale.yml

* chore: add or force update .github/workflows/generated-pr.yml
---------

Co-authored-by: Anton Nashatyrev <Nashatyrev@users.noreply.github.com>
fixed the problem of openjdk images being gone
* Updated rpc protobuf definition for partial messages

* fix spaces

* fix typo
…xChannel.doWrite

In Netty 4.2.x the original code's throw+catch pattern caused the exception to
escape doWrite() uncaught, surfacing as spurious "PLEASE FIX OR REPORT" noise in
Teku logs. The throw was caught locally, but buf.remove(cause) — called from the
catch block without its own guard — can propagate exceptions back through
promise-listener callbacks in certain Netty versions.

Fix: move the localDisconnected check outside the try/catch and wrap the
buf.remove(cause) call defensively so nothing can escape doWrite(). Pending write
promises are still properly failed with ConnectionClosedException.
@lucassaldanha lucassaldanha deleted the fix-log branch April 20, 2026 20:55
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.

9 participants