-
Notifications
You must be signed in to change notification settings - Fork 5k
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
transactions - run event emitters outside context of _setTxStatus #4131
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
frankiebee
force-pushed
the
emitter-cleanup
branch
from
April 29, 2018 23:08
6ac624c
to
a71b49c
Compare
frankiebee
force-pushed
the
emitter-cleanup
branch
from
April 29, 2018 23:32
a71b49c
to
7eb7356
Compare
frankiebee
force-pushed
the
emitter-cleanup
branch
from
April 29, 2018 23:35
58672df
to
7066477
Compare
kumavis
reviewed
Apr 30, 2018
this.updateTx(txMeta, `txStateManager: setting status to ${status}`) | ||
this.emit(`${txMeta.id}:${status}`, txId) | ||
this.emit(`tx:status-update`, txId, status) | ||
if (['submitted', 'rejected', 'failed'].includes(status)) { |
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.
we should break this utility out
kumavis
approved these changes
Apr 30, 2018
Gudahtt
added a commit
that referenced
this pull request
May 9, 2020
All transaction status updates were moved into a `setTimeout` callback and wrapped in a `try...catch` block in #4131, apparently in an attempt to prevent failures in event subscribers from interrupting the transaction logic. The `try...catch` block did accomplish that, but by putting the status update in a `setTimeout` callback the operation was made asynchronous. Transaction status updates now happen unpredictably, in some future event loop from when they're triggered. This creates a race condition, where the transaction status update may occur before or after subsequent state changes. This also introduces a risk of accidentally undoing a change to the transaction state, as the update made to the transaction inside the `setTimeout` callback uses a reference to `txMeta` obtained synchronously before the `setTimeout` call. Any replacement of the `txMeta` between the `setTxStatus` call and the execution of the timeout would be erased. Luckily the `txMeta` object is more often than not mutated rather than replaced, which may explain why we haven't seen this happen yet. Everything seems to work correctly with the `setTimeout` call removed, and now the transaction logic is easier to understand.
Gudahtt
added a commit
that referenced
this pull request
May 9, 2020
All transaction status updates were moved into a `setTimeout` callback and wrapped in a `try...catch` block in #4131, apparently in an attempt to prevent failures in event subscribers from interrupting the transaction logic. The `try...catch` block did accomplish that, but by putting the status update in a `setTimeout` callback the operation was made asynchronous. Transaction status updates now happen unpredictably, in some future event loop from when they're triggered. This creates a race condition, where the transaction status update may occur before or after subsequent state changes. This also introduces a risk of accidentally undoing a change to the transaction state, as the update made to the transaction inside the `setTimeout` callback uses a reference to `txMeta` obtained synchronously before the `setTimeout` call. Any replacement of the `txMeta` between the `setTxStatus` call and the execution of the timeout would be erased. Luckily the `txMeta` object is more often than not mutated rather than replaced, which may explain why we haven't seen this happen yet. Everything seems to work correctly with the `setTimeout` call removed, and now the transaction logic is easier to understand.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
this wraps emitters so they excute safely