fix(tcp): unregister ActivityConnectionObserver on connection dispose to prevent memory leak - #6453
Open
wy471x wants to merge 1 commit into
Open
fix(tcp): unregister ActivityConnectionObserver on connection dispose to prevent memory leak#6453wy471x wants to merge 1 commit into
wy471x wants to merge 1 commit into
Conversation
… to prevent memory leak Per-connection observers were registered on the shared EventBus but never unregistered, causing stale observers to accumulate. Added onDispose cleanup and error handling for failed downstream connections. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Per-connection observers were registered on the shared EventBus but never
unregistered, causing stale observers to accumulate. Added onDispose cleanup
and error handling for failed downstream connections.
Per-connection observers were registered on the shared EventBus but never unregistered, causing stale observers to accumulate. Added onDispose cleanup and error handling for failed downstream connections.
Make sure that:
./mvnw clean install -Dmaven.javadoc.skip=true.Summary of Changes
Problem
Every inbound TCP connection in TcpBootstrapServer.bridgeConnections() created a new
ActivityConnectionObserver and registered it on the shared EventBus, but never unregistered it.
This caused:
references in their cache map
not just active ones
never disposed and no error was logged
Fix (TcpBootstrapServer.java)
Two changes in bridgeConnections():
is unregistered from the EventBus when the connection terminates
disposes the server connection, and logs the error
Tests (TcpBootstrapServerTest.java — new file)
4 unit tests covering the lifecycle:
Test: shouldUnregisterObserverWhenServerConnectionIsDisposed
What it verifies: Observer is unregistered when the server connection disposes
────────────────────────────────────────
Test: shouldUnregisterObserverAndDisposeServerConnOnClientConnectionError
What it verifies: On client connection failure, observer is unregistered and serverConn is
disposed
────────────────────────────────────────
Test: shouldBridgeConnectionsOnSuccessfulClientConnection
What it verifies: On success, bridge.bridge() is called with correct connections
────────────────────────────────────────
Test: shouldUseSameObserverForEventBusAndConnectionContext
What it verifies: The same observer instance is used for both EventBus registration and
connection observation
close #6448