Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions src/cloud-sql-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
}
}
Expand Down
28 changes: 28 additions & 0 deletions test/cloud-sql-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Error | undefined> = [];
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 => {
Expand Down