node-mysql2 icon indicating copy to clipboard operation
node-mysql2 copied to clipboard

end of connection more then once

Open talGibly1 opened this issue 3 years ago • 5 comments

When we close the pool connection it call the close of the connection and then call the callback. When we do it twice the callback not call.

The suggested solution is: At the connection end function we first check if already closed

end(callback) { if(this._closing){ return callback(); } this._closing = true; if (this.config.isServer) { const quitCmd = new EventEmitter(); setImmediate(() => { this.stream.end(); quitCmd.emit('end'); }); return quitCmd; } // trigger error if more commands enqueued after end command const quitCmd = this.addCommand(new Commands.Quit(callback)); this.addCommand = this._addCommandClosedState; return quitCmd; }

talGibly1 avatar Jun 22 '21 10:06 talGibly1

Yes, when calling the end method of the connection more then once the callback function not called. Maybe because internal unhandle error..

We using Marria DB Maybe it's related..

naor88 avatar Jun 22 '21 13:06 naor88

Why do need call the callback function more than once?

codinggirl avatar Jul 05 '21 07:07 codinggirl

@talGibly1 Agree, that should work. would you like to submit a PR?

sidorares avatar Jul 05 '21 07:07 sidorares

@codinggirl We don't call the callback more then once we call the end method more then once. We do it by mistake at one of our integration tests. The test never finish and any error not occur.

naor88 avatar Jul 05 '21 08:07 naor88

I think the right behavior should be that if you call end() more than once, the second time, it should fail.

testn avatar Oct 28 '21 14:10 testn