Memory leak with sockets (SSLSocketImpl) in MonitoredCache #2129
Labels
priority: p0
Highest priority. Critical issue. P0 implies highest priority.
type: bug
Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Bug Description
After upgrading
cloud-sql-connector-jdbc-sqlserver
from1.23.1
to version1.24.0
we have experienced several occasional memory leaks in a couple of our applications after running for a hours or even days.InternalConnectorRegistry
holds a map ofunnamedConnectors
. One of the entries in that map is an instance ofMonitoredCache
that seems to have been introduced in #2056MonitoredCache
has a fieldList<Socket> sockets
, and when we observe the memory leak, this list has grown to a large size. In our last case, this list held 91568 instances ofsun.security.ssl.SSLSocketImpl
with a total memory consumption 3.7GB according to the heap dump.https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory/blob/v1.24.0/core/src/main/java/com/google/cloud/sql/core/MonitoredCache.java#L41
Applications can run for days before this happens, We have not figured out what the trigger is. (Our applications have used the
cloud-sql-connector-jdbc-sqlserver
dependency for years without issues, and the memory leak did only occur after the upgrade to1.24.0
)The screenshot below shows the relevant part from the heap dump taken from the application during the memory leak. It has been imported into Intellij for investigation, and it clearly shows the memory consumption in relation to

MonitoredCache.sockets
:Relevant parts of dependency tree
Application runs in kubernetes on GKE with the base image
eclipse-temurin:21-jre-alpine
. Java application is built with jib maven plugin3.4.4
and java compile/release version is 21. Application consumes messages from pubsub pull and writes to a mssql database using the socket factoryExample code (or command)
Stacktrace
Steps to reproduce?
It is hard to reproduce this memory leak issue. Will provide more information if possible.
Environment
Additional Details
No response
The text was updated successfully, but these errors were encountered: