wy471x opened a new pull request, #6453: URL: https://github.com/apache/shenyu/pull/6453
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. <!-- Describe your PR here; e.g. Fixes #issueNo --> <!-- Thank you for proposing a pull request. This template will guide you through the essential steps necessary for a pull request. --> Make sure that: - [X] You have read the [contribution guidelines](https://shenyu.apache.org/community/contributor-guide). - [X] You submit test cases (unit or integration tests) that back your changes. - [X] Your local test passed `./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: 1. Memory leak — dead observers accumulated in the EventBus, each holding stale Connection references in their cache map 2. Fan-out waste — each removeCommonUpstream() event was posted to every observer ever created, not just active ones 3. Orphaned connections — when the downstream client connection failed, the serverConn was never disposed and no error was logged ### Fix (TcpBootstrapServer.java) Two changes in bridgeConnections(): 1. serverConn.onDispose(() -> eventBus.unregister(connectionObserver)) — ensures the observer is unregistered from the EventBus when the connection terminates 2. Error handler on client.subscribe() — on failure, immediately unregisters the observer, 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 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
