From 6d38ac1c4670ad553ec845abf272007fd41375a5 Mon Sep 17 00:00:00 2001 From: sahil Date: Tue, 24 Apr 2018 12:33:46 +0530 Subject: [PATCH 1/4] set txid to null, so that no further queries can be executed in the same transaction --- lib/transaction.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/transaction.js b/lib/transaction.js index e20b9575..8e5ede77 100644 --- a/lib/transaction.js +++ b/lib/transaction.js @@ -67,6 +67,12 @@ function mixinTransaction(PostgreSQL) { self.releaseConnection(connection, err); cb(err); }); + //If we don't set txId to null and wait for the callback + //of ROLLBACK query to execute, another query can be executed in the + //same transaction because the callback will be called asynchronously + if (typeof connection.autorelease === 'function') { + connection.txId = null; + } }; PostgreSQL.prototype.releaseConnection = function(connection, err) { From c3ee5d7995fa2ae63b326c705529218f97b8920d Mon Sep 17 00:00:00 2001 From: sahil Date: Tue, 24 Apr 2018 12:48:33 +0530 Subject: [PATCH 2/4] fix lint error --- lib/transaction.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/transaction.js b/lib/transaction.js index 8e5ede77..280f821c 100644 --- a/lib/transaction.js +++ b/lib/transaction.js @@ -69,7 +69,7 @@ function mixinTransaction(PostgreSQL) { }); //If we don't set txId to null and wait for the callback //of ROLLBACK query to execute, another query can be executed in the - //same transaction because the callback will be called asynchronously + //same transaction because the callback will be called asynchronously if (typeof connection.autorelease === 'function') { connection.txId = null; } From 200910a0bbc5d516b286db0fe28a6ff7371f4289 Mon Sep 17 00:00:00 2001 From: sahil Date: Tue, 24 Apr 2018 12:33:46 +0530 Subject: [PATCH 3/4] set txid to null synchronously so that no further queries can be executed in the same transaction after rollback has been executed --- lib/transaction.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/transaction.js b/lib/transaction.js index e20b9575..8e5ede77 100644 --- a/lib/transaction.js +++ b/lib/transaction.js @@ -67,6 +67,12 @@ function mixinTransaction(PostgreSQL) { self.releaseConnection(connection, err); cb(err); }); + //If we don't set txId to null and wait for the callback + //of ROLLBACK query to execute, another query can be executed in the + //same transaction because the callback will be called asynchronously + if (typeof connection.autorelease === 'function') { + connection.txId = null; + } }; PostgreSQL.prototype.releaseConnection = function(connection, err) { From 0e4007c4efc9d1324f54316f4957beea1e66dd03 Mon Sep 17 00:00:00 2001 From: sahil Date: Tue, 24 Apr 2018 12:48:33 +0530 Subject: [PATCH 4/4] fix lint error --- lib/transaction.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/transaction.js b/lib/transaction.js index 8e5ede77..280f821c 100644 --- a/lib/transaction.js +++ b/lib/transaction.js @@ -69,7 +69,7 @@ function mixinTransaction(PostgreSQL) { }); //If we don't set txId to null and wait for the callback //of ROLLBACK query to execute, another query can be executed in the - //same transaction because the callback will be called asynchronously + //same transaction because the callback will be called asynchronously if (typeof connection.autorelease === 'function') { connection.txId = null; }