Skip to content
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

timers: fix arbitrary object clearImmediate errors #37824

Merged
merged 1 commit into from
Mar 28, 2021

Conversation

Linkgoron
Copy link
Member

@Linkgoron Linkgoron commented Mar 19, 2021

Fix errors that are caused by invoking clearImmediate with arbitrary objects. (e.g. clearImmediate({}))

  • Fix in timers.js fixes the REPL crash.
  • Fix in internal/timers.js fixes another error that gets thrown.

Both of the above already exist in the clearTimeout path.

Fixes: #37806

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout. labels Mar 19, 2021
@nodejs-github-bot
Copy link
Collaborator

@addaleax
Copy link
Member

Can you add regression tests for these?

@Linkgoron
Copy link
Member Author

Linkgoron commented Mar 20, 2021

Can you add regression tests for these?

Done. I'm not 100% happy with the non-REPL test, as looking at the code even sending regular objects to clearImmediate looks like it has some side-effects which might corrupt some state, but it doesn't throw now.

@nodejs-github-bot
Copy link
Collaborator

proc.on('exit', common.mustCall((code) => {
assert.strictEqual(code, 0);
}));
proc.stdin.write('clearImmediate({});\n.exit\n');
Copy link
Member

Choose a reason for hiding this comment

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

This test is not really required, since it was just caused by the crash but it does not hurt either.

Copy link
Member Author

@Linkgoron Linkgoron Mar 20, 2021

Choose a reason for hiding this comment

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

The issue, I think, was a bit different (if by "the crash" you mean that NRE for this._idleNext). The REPL crash was caused because an undefined async_id was given to emitDestroy, and this caused an error in emitDestroyScript (as the check there only checks <= 0 and undefined is not <= 0).

Copy link
Member Author

@Linkgoron Linkgoron Mar 20, 2021

Choose a reason for hiding this comment

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

Maybe a better fix would've been to actually change the code there (in async_hooks.js) to check for hasHooks(kDestroy) && asyncId > 0 instead of an early return - but that's probably out of scope for this minor issue, and maybe a crash there is better than "swallowing" bad async_ids which might cover errors elsewhere.

@Linkgoron Linkgoron added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Mar 20, 2021
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

Fix errors that are caused by invoking clearImmediate
with arbitrary objects.

fixes: nodejs#37806

PR-URL: nodejs#37824
Fixes: nodejs#37806
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
@aduh95 aduh95 merged commit fcc934f into nodejs:master Mar 28, 2021
@aduh95
Copy link
Contributor

aduh95 commented Mar 28, 2021

Landed in fcc934f

ruyadorno pushed a commit that referenced this pull request Mar 29, 2021
Fix errors that are caused by invoking clearImmediate
with arbitrary objects.

fixes: #37806

PR-URL: #37824
Fixes: #37806
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
ruyadorno pushed a commit that referenced this pull request Mar 30, 2021
Fix errors that are caused by invoking clearImmediate
with arbitrary objects.

fixes: #37806

PR-URL: #37824
Fixes: #37806
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
@ruyadorno ruyadorno mentioned this pull request Mar 30, 2021
targos pushed a commit that referenced this pull request May 1, 2021
Fix errors that are caused by invoking clearImmediate
with arbitrary objects.

fixes: #37806

PR-URL: #37824
Fixes: #37806
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
@danielleadams danielleadams mentioned this pull request May 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. needs-ci PRs that need a full CI run. timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"clearImmediate" results in an abort
7 participants