Skip to content

fix(zone.js): store remove abort listener on the scheduled task#56160

Closed
arturovt wants to merge 1 commit intoangular:mainfrom
arturovt:fix/56148
Closed

fix(zone.js): store remove abort listener on the scheduled task#56160
arturovt wants to merge 1 commit intoangular:mainfrom
arturovt:fix/56148

Conversation

@arturovt
Copy link
Copy Markdown
Contributor

Prior to this commit, a memory leak occurred when the abort listener was not removed from the AbortSignal. We introduced a fix to remove the event listener, but it was erroneously stored on the taskData, which is a shared global object. Consequently, when something attempted to remove an event listener, it immediately removed the last stored abort listener. As a result, events would never be canceled.

We have now rectified this by storing the remove abort listener function directly on the task itself. This adjustment ensures that the abort listener is tied only to the specific task. When the abort function is called, it cancels the task. Therefore, it is safe to associate the cleanup function directly with the task.

Closes: #56148

@arturovt arturovt marked this pull request as ready for review May 29, 2024 17:35
@pullapprove pullapprove Bot requested a review from JiaLiPassion May 29, 2024 17:35
@thePunderWoman thePunderWoman added the area: zones Issues related to zone.js label May 29, 2024
@ngbot ngbot Bot added this to the Backlog milestone May 29, 2024
@thePunderWoman thePunderWoman added target: patch This PR is targeted for the next patch release action: review The PR is still awaiting reviews from at least one requested reviewer labels May 29, 2024
@AndrewKushnir AndrewKushnir added the requires: TGP This PR requires a passing TGP before merging is allowed label May 30, 2024
@pullapprove pullapprove Bot removed the requires: TGP This PR requires a passing TGP before merging is allowed label May 30, 2024
Copy link
Copy Markdown
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arturovt thanks for the fix, I've just left a minor comment.

@JiaLiPassion could you please take a look at this fix when you get a chance?

Comment thread packages/zone.js/lib/common/events.ts Outdated
Prior to this commit, a memory leak occurred when the `abort` listener was
not removed from the `AbortSignal`. We introduced a fix to remove the event
listener, but it was erroneously stored on the `taskData`, which is a shared
global object. Consequently, when something attempted to remove an event listener,
it immediately removed the last stored abort listener. As a result, events would
never be canceled.

We have now rectified this by storing the remove abort listener function directly on
the task itself. This adjustment ensures that the abort listener is tied only to the
specific task. When the `abort` function is called, it cancels the task. Therefore, it
is safe to associate the cleanup function directly with the task.

Closes: angular#56148
Copy link
Copy Markdown
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arturovt thanks for addressing the feedback 👍

@AndrewKushnir AndrewKushnir added the regression Indicates than the issue relates to something that worked in a previous version label May 31, 2024
Copy link
Copy Markdown
Contributor

@JiaLiPassion JiaLiPassion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks.

@AndrewKushnir AndrewKushnir added action: global presubmit The PR is in need of a google3 global presubmit and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Jun 4, 2024
@AndrewKushnir
Copy link
Copy Markdown
Contributor

Global Presubmit.

@AndrewKushnir AndrewKushnir added action: merge The PR is ready for merge by the caretaker merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note and removed action: global presubmit The PR is in need of a google3 global presubmit labels Jun 4, 2024
@AndrewKushnir
Copy link
Copy Markdown
Contributor

Caretaker note: TGP is "green", this PR is ready for merge.

thePunderWoman pushed a commit that referenced this pull request Jun 4, 2024
Prior to this commit, a memory leak occurred when the `abort` listener was
not removed from the `AbortSignal`. We introduced a fix to remove the event
listener, but it was erroneously stored on the `taskData`, which is a shared
global object. Consequently, when something attempted to remove an event listener,
it immediately removed the last stored abort listener. As a result, events would
never be canceled.

We have now rectified this by storing the remove abort listener function directly on
the task itself. This adjustment ensures that the abort listener is tied only to the
specific task. When the `abort` function is called, it cancels the task. Therefore, it
is safe to associate the cleanup function directly with the task.

Closes: #56148

PR Close #56160
@thePunderWoman
Copy link
Copy Markdown
Contributor

This PR was merged into the repository by commit 4a3800a.

@arturovt arturovt deleted the fix/56148 branch June 4, 2024 17:45
@angular-automatic-lock-bot
Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Jul 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: zones Issues related to zone.js merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note regression Indicates than the issue relates to something that worked in a previous version target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AbortController with zone.js not working anymore

4 participants