From 1f7f62acca04e6de54accdad52a81b8209a691ee Mon Sep 17 00:00:00 2001 From: Haihan Jiang Date: Sat, 23 May 2026 13:33:43 -0700 Subject: [PATCH] fix: close sockets without synthetic error --- src/cloud-sql-instance.ts | 8 +------- test/cloud-sql-instance.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/cloud-sql-instance.ts b/src/cloud-sql-instance.ts index 3dc2e329..25e9437d 100644 --- a/src/cloud-sql-instance.ts +++ b/src/cloud-sql-instance.ts @@ -25,7 +25,6 @@ import {RSAKeys} from './rsa-keys'; import {SslCert} from './ssl-cert'; import {getRefreshInterval, isExpirationTimeValid} from './time'; import {AuthTypes} from './auth-types'; -import {CloudSQLConnectorError} from './errors'; // Private types that describe exactly the methods // needed from tls.Socket to be able to close @@ -365,12 +364,7 @@ export class CloudSQLInstance { } for (const socket of this.sockets) { if (typeof socket.destroy === 'function') { - socket.destroy( - new CloudSQLConnectorError({ - code: 'ERRCLOSED', - message: 'The connector was closed.', - }) - ); + socket.destroy(); } } } diff --git a/test/cloud-sql-instance.ts b/test/cloud-sql-instance.ts index 9b4c2471..39c1cc45 100644 --- a/test/cloud-sql-instance.ts +++ b/test/cloud-sql-instance.ts @@ -552,6 +552,34 @@ t.test('CloudSQLInstance', async t => { } ); + t.test('close destroys tracked sockets without an error', async t => { + const instance = new CloudSQLInstance({ + options: { + ipType: IpAddressTypes.PUBLIC, + authType: AuthTypes.PASSWORD, + instanceConnectionName: 'my-project:us-east1:my-instance', + sqlAdminFetcher: fetcher, + }, + }); + + const destroyArgs: Array = []; + const socket = { + destroy(error?: Error) { + destroyArgs.push(error); + }, + once() {}, + }; + + instance.addSocket(socket); + instance.close(); + + t.same( + destroyArgs, + [undefined], + 'close should not emit a synthetic socket error' + ); + }); + t.test( 'get invalid certificate data while having a current valid', async t => {