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 race condition in non-container transactions #3671
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -74,13 +74,7 @@ class Transaction extends EventEmitter { | |||||||||||||||||||
return makeTransactor(this, connection, trxClient); | ||||||||||||||||||||
}) | ||||||||||||||||||||
.then((transactor) => { | ||||||||||||||||||||
if (this.initPromise) { | ||||||||||||||||||||
transactor.executionPromise = executionPromise.catch((err) => { | ||||||||||||||||||||
throw err; | ||||||||||||||||||||
}); | ||||||||||||||||||||
} else { | ||||||||||||||||||||
transactor.executionPromise = executionPromise; | ||||||||||||||||||||
} | ||||||||||||||||||||
transactor.executionPromise = executionPromise; | ||||||||||||||||||||
|
||||||||||||||||||||
// If we've returned a "thenable" from the transaction container, assume | ||||||||||||||||||||
// the rollback and commit are chained to this object's success / failure. | ||||||||||||||||||||
|
@@ -225,12 +219,11 @@ class Transaction extends EventEmitter { | |||||||||||||||||||
.then((connection) => { | ||||||||||||||||||||
connection.__knexTxId = this.txid; | ||||||||||||||||||||
|
||||||||||||||||||||
return (this._previousSibling | ||||||||||||||||||||
? this._previousSibling.catch(() => {}) | ||||||||||||||||||||
: Promise.resolve() | ||||||||||||||||||||
).then(function() { | ||||||||||||||||||||
return connection; | ||||||||||||||||||||
}); | ||||||||||||||||||||
return this._previousSibling | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. acquireConnection also has overrides in several dialects, check them please There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Lines 216 to 224 in 7288608
So, there isn't actually an inheritance relationship there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, nvm. I see what you mean. I'll check it in a little bit. (Related note: seems like there is a lot of duplication within those implementations) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, the other implementations are actually ignoring the details around |
||||||||||||||||||||
.catch(() => {}) // TODO: Investigate this line | ||||||||||||||||||||
.then(function() { | ||||||||||||||||||||
return connection; | ||||||||||||||||||||
}); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was just a minor code cleanup. It turns out that Additionally, take note of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually... I suspect that the I'm going to test out a different implementation that will (hopefully!) allow for proper sibling->sibling linking without swallowing exceptions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright -- I just pushed the code for establishing 2 separate Promise Chains. So, instead of doing this:
It is doing this:
|
||||||||||||||||||||
}) | ||||||||||||||||||||
.then(async (connection) => { | ||||||||||||||||||||
try { | ||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maximelkin : I'm fairly certain that this change is the one that fixed the race condition.
Your PR (#3665) included this change as well; however, it relocated the
.catch((err)=> {throw err})
logic to a different part of the code. In contrast, this PR just removes that logic entirely.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This catch added in #3328, so I am unsure about this changes