From cde8c7d3dbe68efc3e0c664872c3dfcf80835f7c Mon Sep 17 00:00:00 2001 From: Brian Lauber Date: Fri, 14 Feb 2020 19:56:30 -0500 Subject: [PATCH 1/2] Fixed unresolved promise in cancelQuery(..) ... ... more specifically: cancelQuery(..) was attempting to "cancel the cancellation" after 100ms. However, it was not actually achieving this objective. In reality, the cancellation was still running in the background even though the caller had already moved on. Later on, the cancellation would ACTUALLY fail due to a resource allocation issue (ie: no more connections in the Tarn pool). This would then result in an unhandled Promise rejection. --- lib/dialects/mysql/index.js | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/lib/dialects/mysql/index.js b/lib/dialects/mysql/index.js index 0c18c05180..bf1f0e3683 100644 --- a/lib/dialects/mysql/index.js +++ b/lib/dialects/mysql/index.js @@ -171,27 +171,18 @@ Object.assign(Client_MySQL.prototype, { canCancelQuery: true, - cancelQuery(connectionToKill) { - const acquiringConn = this.acquireConnection(); - - // Error out if we can't acquire connection in time. - // Purposely not putting timeout on `KILL QUERY` execution because erroring - // early there would release the `connectionToKill` back to the pool with - // a `KILL QUERY` command yet to finish. - return timeout(acquiringConn, 100) - .then((conn) => - this.query(conn, { - method: 'raw', - sql: 'KILL QUERY ?', - bindings: [connectionToKill.threadId], - options: {}, - }) - ) - .finally(() => { - // NOT returning this promise because we want to release the connection - // in a non-blocking fashion - acquiringConn.then((conn) => this.releaseConnection(conn)); + async cancelQuery(connectionToKill) { + const conn = await this.acquireConnection(); + try { + return await this.query(conn, { + method: 'raw', + sql: 'KILL QUERY ?', + bindings: [connectionToKill.threadId], + options: {}, }); + } finally { + await this.releaseConnection(conn); + } }, }); From d17ee7f50ab5ad08f210db31abc6995629b3448f Mon Sep 17 00:00:00 2001 From: Brian Lauber Date: Fri, 14 Feb 2020 20:19:13 -0500 Subject: [PATCH 2/2] Made linter happy. (Removed unused variable) --- lib/dialects/mysql/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/dialects/mysql/index.js b/lib/dialects/mysql/index.js index bf1f0e3683..33ea9a8787 100644 --- a/lib/dialects/mysql/index.js +++ b/lib/dialects/mysql/index.js @@ -4,7 +4,6 @@ const inherits = require('inherits'); const { map, defer } = require('lodash'); const { promisify } = require('util'); const Client = require('../../client'); -const { timeout } = require('../../util/timeout'); const Bluebird = require('bluebird'); const Transaction = require('./transaction');