Skip to content

Commit

Permalink
Fix memory/breaker leaks for outbound responses (#76474) (#76536)
Browse files Browse the repository at this point in the history
Outbound responses would not get the expected `decRef`, resulting in
memory and/or circuit breaker leaks. In particular, the
`GetCcrRestoreFileChunkResponse` expects this, causing a leak when
a follower bootstraps.

Relates #65921
  • Loading branch information
henningandersen committed Aug 15, 2021
1 parent 10b8919 commit 5d668f6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,13 @@ void sendResponse(final Version nodeVersion, final Set<String> features, final T
}
OutboundMessage.Response message = new OutboundMessage.Response(threadPool.getThreadContext(), features, response, version,
requestId, isHandshake, compressionScheme);
ActionListener<Void> listener = ActionListener.wrap(() -> messageListener.onResponseSent(requestId, action, response));
ActionListener<Void> listener = ActionListener.wrap(() -> {
try {
messageListener.onResponseSent(requestId, action, response);
} finally {
response.decRef();
}
});
sendMessage(channel, message, listener);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public T read(StreamInput in) throws IOException {
@Override
public void handleResponse(T response) {
try {
response.incRef();
channel.sendResponse(response);
} catch (IOException e) {
throw new UncheckedIOException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ public void afterTest() throws Exception {
clusterGroup.leaderCluster.wipe(Collections.emptySet());
clusterGroup.followerCluster.wipe(Collections.emptySet());
}

clusterGroup.leaderCluster.assertAfterTest();
clusterGroup.followerCluster.assertAfterTest();
}

private NodeConfigurationSource createNodeConfigurationSource(final String leaderSeedAddress, final boolean leaderCluster) {
Expand Down

0 comments on commit 5d668f6

Please sign in to comment.