From 6025dd2e51d5fad6911e3535d3c0231b746830de Mon Sep 17 00:00:00 2001 From: Arthur Schreiber Date: Wed, 19 Jun 2024 08:33:22 +0000 Subject: [PATCH 1/2] Add some debug output. --- src/connection.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/connection.ts b/src/connection.ts index 6f368d163..acf6ed7f7 100644 --- a/src/connection.ts +++ b/src/connection.ts @@ -1033,6 +1033,10 @@ class Connection extends EventEmitter { */ declare databaseCollation: Collation | undefined; + private onSocketError: (error: Error) => void; + private onSocketClose: () => void; + private onSocketEnd: () => void; + /** * Note: be aware of the different options field: * 1. config.authentication.options @@ -1742,6 +1746,10 @@ class Connection extends EventEmitter { this.state = this.STATE.INITIALIZED; + this.onSocketError = (error: Error) => { this.socketError(error); }; + this.onSocketClose = () => { this.socketClose(); }; + this.onSocketEnd = () => { this.socketEnd(); }; + this._cancelAfterRequestSent = () => { this.messageIo.sendMessage(TYPE.ATTENTION); this.createCancelTimer(); @@ -1992,9 +2000,9 @@ class Connection extends EventEmitter { } socketHandlingForSendPreLogin(socket: net.Socket) { - socket.on('error', (error) => { this.socketError(error); }); - socket.on('close', () => { this.socketClose(); }); - socket.on('end', () => { this.socketEnd(); }); + socket.on('error', this.onSocketError); + socket.on('close', this.onSocketClose); + socket.on('end', this.onSocketEnd); socket.setKeepAlive(true, KEEP_ALIVE_INITIAL_DELAY); this.messageIo = new MessageIO(socket, this.config.options.packetSize, this.debug); @@ -3395,6 +3403,8 @@ Connection.prototype.STATE = { if (handler.loginAckReceived) { if (handler.routingData) { this.routingData = handler.routingData; + + console.log('socket closed before rerouting?', this.socket?.closed); this.transitionTo(this.STATE.REROUTING); } else { this.transitionTo(this.STATE.LOGGED_IN_SENDING_INITIAL_SQL); @@ -3446,6 +3456,7 @@ Connection.prototype.STATE = { if (handler.loginAckReceived) { if (handler.routingData) { this.routingData = handler.routingData; + console.log('socket closed before rerouting?', this.socket?.closed); return this.transitionTo(this.STATE.REROUTING); } else { return this.transitionTo(this.STATE.LOGGED_IN_SENDING_INITIAL_SQL); @@ -3512,6 +3523,7 @@ Connection.prototype.STATE = { if (handler.loginAckReceived) { if (handler.routingData) { this.routingData = handler.routingData; + console.log('socket closed before rerouting?', this.socket?.closed); this.transitionTo(this.STATE.REROUTING); } else { this.transitionTo(this.STATE.LOGGED_IN_SENDING_INITIAL_SQL); From 2154afd1a26adc79d64a72b6f825a68085266e3b Mon Sep 17 00:00:00 2001 From: Arthur Schreiber Date: Wed, 19 Jun 2024 08:46:16 +0000 Subject: [PATCH 2/2] Try this. --- src/connection.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/connection.ts b/src/connection.ts index acf6ed7f7..a3ba49471 100644 --- a/src/connection.ts +++ b/src/connection.ts @@ -1764,16 +1764,25 @@ class Connection extends EventEmitter { if (connectListener) { const onConnect = (err?: Error) => { this.removeListener('error', onError); + this.removeListener('end', onEnd); connectListener(err); }; const onError = (err: Error) => { this.removeListener('connect', onConnect); + this.removeListener('end', onEnd); connectListener(err); }; + const onEnd = () => { + this.removeListener('connect', onConnect); + this.removeListener('error', onError); + connectListener(new Error('unexpected connection end during connect')); + } + this.once('connect', onConnect); this.once('error', onError); + this.once('end', onEnd); } this.transitionTo(this.STATE.CONNECTING);