Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for concurrent child transactions failing (#2213) #3440

Merged
merged 3 commits into from Sep 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/transaction.js
Expand Up @@ -210,6 +210,7 @@ class Transaction extends EventEmitter {
// the original promise is marked completed.
acquireConnection(client, config, txid) {
const configConnection = config && config.connection;
const trx = this;
return new Bluebird((resolve, reject) => {
try {
resolve(configConnection || client.acquireConnection());
Expand All @@ -220,7 +221,10 @@ class Transaction extends EventEmitter {
.then(function(connection) {
connection.__knexTxId = txid;

return connection;
return (trx._previousSibling ? trx._previousSibling.reflect() : Promise.resolve())
.then(function () {
return connection;
});
})
.disposer(function(connection) {
if (!configConnection) {
Expand Down
21 changes: 21 additions & 0 deletions test/integration/builder/transaction.js
Expand Up @@ -399,6 +399,27 @@ module.exports = function(knex) {
});
});

it('#2213 - should wait for sibling transactions to finish', function() {
if (/redshift/i.test(knex.client.driverName)) {
return Promise.resolve();
}
if (/mssql/i.test(knex.client.driverName)) {
return Promise.resolve();
}
const first = Bluebird.delay(50);
const second = first.then(() => Bluebird.delay(50));
return knex.transaction(function(trx) {
return Promise.all([
trx.transaction(function(trx2) {
return first;
}),
trx.transaction(function(trx3) {
return second;
}),
]);
});
});

it('#855 - Query Event should trigger on Transaction Client AND main Client', function() {
let queryEventTriggered = false;

Expand Down