Skip to content

fix: only keep track of sockets opened using domain name#2130

Merged
hessjcg merged 2 commits intomainfrom
socket-memory-leak
Mar 27, 2025
Merged

fix: only keep track of sockets opened using domain name#2130
hessjcg merged 2 commits intomainfrom
socket-memory-leak

Conversation

@jackwotherspoon
Copy link
Copy Markdown
Collaborator

@jackwotherspoon jackwotherspoon commented Mar 27, 2025

The list sockets on the MonitoredCache should only keep track of
sockets opened for connections using a domain name.

It should not keep track of all sockets for regular connections.

This is what it is currently doing:

Sockets are only removed from the list if the connections were made using a domain name:

synchronized (sockets) {
for (Iterator<Socket> it = sockets.iterator(); it.hasNext(); ) {
Socket socket = it.next();
if (socket.isClosed()) {
it.remove();

Thus for sockets not using a domain name and using the default instance connection name pattern, the sockets list will continue to grow and grow without being cleaned up.

This PR adds the proper check to gate adding to the sockets list for only connections using a domain name.

Fixes #2129

@jackwotherspoon jackwotherspoon self-assigned this Mar 27, 2025
@jackwotherspoon jackwotherspoon requested a review from a team as a code owner March 27, 2025 13:29
@jackwotherspoon
Copy link
Copy Markdown
Collaborator Author

@hessjcg do you mind adding a unit test to verify that the Connector using an instance connection name does not add to the socket list?

@hessjcg hessjcg force-pushed the socket-memory-leak branch from 959c877 to b39440d Compare March 27, 2025 15:39
@jackwotherspoon
Copy link
Copy Markdown
Collaborator Author

LGTM, thanks for the tests! ✅

@hessjcg hessjcg merged commit 071085c into main Mar 27, 2025
17 checks passed
@hessjcg hessjcg deleted the socket-memory-leak branch March 27, 2025 15:50
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.

Memory leak with sockets (SSLSocketImpl) in MonitoredCache

2 participants