This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
fix(task): fix #778, sometimes task will run after being canceled #780
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.
fix #778.
In normal case, ZoneTask can only transit to
running
state fromscheduled
state.But in some complex cases, ZoneTask will try to run after being canceled.
The case above describe such issue.
Be simplified, a
target
have2
listeners for1
event, and when the event trigger, the1st
event listener remove the2nd
, and then2nd
listener run will cause this issue.The detailed process is:
keypress
event on ReadableStream target.line
Observable.keypress
eventlisteners (2 listeners) will begin to run.createInterface
listener https://github.com/nodejs/node/blob/master/lib/readline.js#L187 will run normally, and triggerline
Observableline
Observable will then triggerkeypress
Observablekeypress
Observable will auto dispose and being removed from ReadableStream, so the Task is canceledone
listener, but in memory listeners from the beginning still have 2It is a little tricky, I tried without zone.js, the removed listener will also run again but do nothing (in this case, the observable has been stopped).
So in this PR, I just check whether ZoneTask is
notScheduled
(canceled) or not before runTask, if it is the case, just return and do nothing.