From ae3edebfa98fb39679f84df641a09ab67fa721f8 Mon Sep 17 00:00:00 2001 From: Dmitry Shohov Date: Mon, 16 Dec 2024 14:20:22 +0200 Subject: [PATCH] #2121 - clear subscriptionForId map after websocket disconnects Signed-off-by: Dmitry Shohov --- CHANGELOG.md | 1 + .../java/org/web3j/protocol/websocket/WebSocketService.java | 2 ++ 2 files changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48a9672834..16f9b25475 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline * fixed several code issues found by sonar [#2113](https://github.com/hyperledger/web3j/pull/2113) * update GitHub actions versions [#2114](https://github.com/hyperledger/web3j/pull/2114) +* fixed subscription object leaking after disconnect [#2121](https://github.com/hyperledger/web3j/pull/2121) ### Features diff --git a/core/src/main/java/org/web3j/protocol/websocket/WebSocketService.java b/core/src/main/java/org/web3j/protocol/websocket/WebSocketService.java index 8012cca728..107ba4a0d3 100644 --- a/core/src/main/java/org/web3j/protocol/websocket/WebSocketService.java +++ b/core/src/main/java/org/web3j/protocol/websocket/WebSocketService.java @@ -557,6 +557,7 @@ private void closeOutstandingRequests() { request.getOnReply() .completeExceptionally( new IOException("Connection was closed"))); + requestForId.clear(); } private void closeOutstandingSubscriptions() { @@ -567,6 +568,7 @@ private void closeOutstandingSubscriptions() { subscription .getSubject() .onError(new IOException("Connection was closed"))); + subscriptionForId.clear(); } // Method visible for unit-tests