Skip to content

Conversation

@Qard
Copy link
Member

@QardQard commented Oct 23, 2020

If exit is called and then run or enterWith are called within the exit function, the als instance should not be added to the storageList additional times. The correct behaviour is to remove the instance from the storageList before executing the exit handler and then to restore it after.

This PR fixes a memory leak wherein an AsyncLocalStorage instance could be repeatedly inserted to the storageList array which keeps track of active instances to call als._propagate(...) on in the shared async_hooks instance.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

@QardQard added confirmed-bug Issues with confirmed bugs. async_hooks Issues and PRs related to the async hooks subsystem. review wanted PRs that need reviews. request-ci Add this label to start a Jenkins CI on a PR. labels Oct 23, 2020
Copy link
Member

@vdeturckheimvdeturckheim 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 a lot @Qard
I feel like _enable() has been added and removed so many times by now ^^

@Qard
Copy link
MemberAuthor

Qard commented Oct 23, 2020

Yep. The other option I considered was wrapping the exit function in another AsyncResource without the storage slot, which I believe we also had at one point but removed due to people thinking the overhead of another AsyncResource was unnecessary. 😅

@Qard
Copy link
MemberAuthor

Qard commented Oct 23, 2020

Whoops...gotta appease that linter. 😅

@github-actionsgithub-actionsbot removed the request-ci Add this label to start a Jenkins CI on a PR. label Oct 23, 2020
@nodejs-github-bot

This comment has been minimized.

Copy link
Member

@mhdawsonmhdawson left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@puzpuzpuzpuzpuzpuz left a comment

Choose a reason for hiding this comment

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

Nice catch!

@codecov-io
Copy link

codecov-io commented Oct 23, 2020

Codecov Report

Merging #35779 into master will increase coverage by 0.22%.
The diff coverage is 100.00%.

@@ Coverage Diff @@## master #35779 +/- ## ========================================== + Coverage 87.92% 88.14% +0.22%  ========================================== Files 477 478 +1 Lines 113090 113536 +446 Branches 24630 25553 +923 ========================================== + Hits 99433 100080 +647 + Misses 7952 7698 -254 - Partials 5705 5758 +53 
Impacted FilesCoverage Δ
lib/async_hooks.js100.00% <100.00%> (ø)
src/connect_wrap.h25.00% <0.00%> (-75.00%)⬇️
lib/internal/repl/history.js88.16% <0.00%> (-4.15%)⬇️
src/api/utils.cc28.57% <0.00%> (-2.86%)⬇️
lib/_http_incoming.js97.47% <0.00%> (-2.53%)⬇️
lib/internal/modules/esm/get_source.js83.33% <0.00%> (-2.39%)⬇️
lib/internal/dns/utils.js98.44% <0.00%> (-1.56%)⬇️
lib/internal/modules/esm/loader.js86.22% <0.00%> (-1.19%)⬇️
src/inspector_profiler.cc76.17% <0.00%> (-1.09%)⬇️
src/node_worker.cc76.56% <0.00%> (-0.96%)⬇️
... and 108 more

@QardQard added the request-ci Add this label to start a Jenkins CI on a PR. label Oct 23, 2020
@github-actionsgithub-actionsbot removed the request-ci Add this label to start a Jenkins CI on a PR. label Oct 23, 2020
@nodejs-github-bot

This comment has been minimized.

@Qard
Copy link
MemberAuthor

Qard commented Oct 23, 2020

Seems to me like that codecov result probably shouldn't be getting reported for an incomplete test run. 🤔

@Qard
Copy link
MemberAuthor

Qard commented Oct 23, 2020

CI doesn't want to cooperate. I keep getting seemingly unrelated errors. 🤔

@nodejs-github-bot

This comment has been minimized.

@Trott

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@puzpuzpuz
Copy link
Member

Created #36079 to follow-up the call stack exceeded issue

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot
Copy link
Collaborator

@FlarnaFlarna added the commit-queue Add this label to land a pull request using GitHub Actions. label Nov 11, 2020
@github-actionsgithub-actionsbot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Nov 11, 2020
@github-actions
Copy link
Contributor

Landed in 39a7f76...06f0d78

nodejs-github-bot pushed a commit that referenced this pull request Nov 11, 2020
If exit is called and then run or enterWith are called within the exit function, the als instace should not be added to the storageList additional times. The correct behaviour is to remove the instance from the storageList before executing the exit handler and then to restore it after. PR-URL: #35779 Reviewed-By: Vladimir de Turckheim <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]> Reviewed-By: Andrey Pechkurov <[email protected]> Reviewed-By: Rich Trott <[email protected]>
@QardQard deleted the fix-als-exit branch November 11, 2020 23:19
@Qard
Copy link
MemberAuthor

Qard commented Nov 16, 2020

This should also get backported as any version the AsyncLocalStorage was backported to would also have this issue.

@FlarnaFlarna added dont-land-on-v10.x and removed review wanted PRs that need reviews. labels Nov 16, 2020
codebytere pushed a commit that referenced this pull request Nov 22, 2020
If exit is called and then run or enterWith are called within the exit function, the als instace should not be added to the storageList additional times. The correct behaviour is to remove the instance from the storageList before executing the exit handler and then to restore it after. PR-URL: #35779 Reviewed-By: Vladimir de Turckheim <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]> Reviewed-By: Andrey Pechkurov <[email protected]> Reviewed-By: Rich Trott <[email protected]>
@codebyterecodebytere mentioned this pull request Nov 22, 2020
BethGriggs pushed a commit that referenced this pull request Dec 9, 2020
If exit is called and then run or enterWith are called within the exit function, the als instace should not be added to the storageList additional times. The correct behaviour is to remove the instance from the storageList before executing the exit handler and then to restore it after. PR-URL: #35779 Reviewed-By: Vladimir de Turckheim <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]> Reviewed-By: Andrey Pechkurov <[email protected]> Reviewed-By: Rich Trott <[email protected]>
BethGriggs pushed a commit that referenced this pull request Dec 10, 2020
If exit is called and then run or enterWith are called within the exit function, the als instace should not be added to the storageList additional times. The correct behaviour is to remove the instance from the storageList before executing the exit handler and then to restore it after. PR-URL: #35779 Reviewed-By: Vladimir de Turckheim <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]> Reviewed-By: Andrey Pechkurov <[email protected]> Reviewed-By: Rich Trott <[email protected]>
@BethGriggsBethGriggs mentioned this pull request Dec 10, 2020
BethGriggs pushed a commit that referenced this pull request Dec 15, 2020
If exit is called and then run or enterWith are called within the exit function, the als instace should not be added to the storageList additional times. The correct behaviour is to remove the instance from the storageList before executing the exit handler and then to restore it after. PR-URL: #35779 Reviewed-By: Vladimir de Turckheim <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]> Reviewed-By: Andrey Pechkurov <[email protected]> Reviewed-By: Rich Trott <[email protected]>
ruyadorno pushed a commit that referenced this pull request Feb 8, 2021
If exit is called and then run or enterWith are called within the exit function, the als instace should not be added to the storageList additional times. The correct behaviour is to remove the instance from the storageList before executing the exit handler and then to restore it after. PR-URL: #35779 Reviewed-By: Vladimir de Turckheim <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]> Reviewed-By: Andrey Pechkurov <[email protected]> Reviewed-By: Rich Trott <[email protected]>
@ruyadornoruyadorno mentioned this pull request Feb 9, 2021
ruyadorno pushed a commit that referenced this pull request Feb 10, 2021
If exit is called and then run or enterWith are called within the exit function, the als instace should not be added to the storageList additional times. The correct behaviour is to remove the instance from the storageList before executing the exit handler and then to restore it after. PR-URL: #35779 Reviewed-By: Vladimir de Turckheim <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]> Reviewed-By: Andrey Pechkurov <[email protected]> Reviewed-By: Rich Trott <[email protected]>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

async_hooksIssues and PRs related to the async hooks subsystem.confirmed-bugIssues with confirmed bugs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants

@Qard@nodejs-github-bot@codecov-io@Trott@Flarna@puzpuzpuz@vdeturckheim@mhdawson@richardlau@BethGriggs