fix: Clean up sockets when closed in startLocalProxy and CloudSQLInstance - #605
Merged
Conversation
…ance When Connector.startLocalProxy() creates socket pairs (the local domain socket and the TLS connection to Cloud SQL), the sockets were added to this.sockets but never removed upon closing. Over time in a long-running process, closed sockets and TLS contexts were leaked. Similarly, CloudSQLInstance.addSocket was listening to 'closed' event instead of Node.js standard 'close' event, preventing closed sockets from being removed. This fix: - Attaches 'close' event listeners to remove both client and stream sockets from Connector.sockets when they close. - Cleans up server from Connector.localProxies upon 'close'. - Fixes the event name in CloudSQLInstance.addSocket from 'closed' to 'close'. - Adds unit test coverage for startLocalProxy and addSocket socket cleanup. BUG=545159743 TAG=agy CONV=badc8593-ab83-4543-91f6-a49f1997305a
kgala2
approved these changes
Aug 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #598
Description
When
Connector.startLocalProxy()creates socket pairs (the local Unix domain socket connection and the TLS connection to Cloud SQL), the sockets were added tothis.socketsbut never removed upon closing. In long-running processes, closed sockets and TLS contexts were retained indefinitely.Additionally,
CloudSQLInstance.addSocketwas listening for a'closed'event instead of the standard Node.js'close'event, preventing closed sockets attached to domain-name instances from being cleaned up.Changes
'close'event listeners on both client sockets and stream sockets inConnector.startLocalProxy()to delete them fromthis.socketswhen closed.'close'event listener on the local proxy server to delete it fromthis.localProxieswhen closed.CloudSQLInstance.addSocketfrom'closed'to'close'.startLocalProxyandCloudSQLInstance.addSocketverifying socket cleanup upon close.