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

Calling clearImmediate on setTimeout return value can make future setTimeout callbacks never run #57063

Open
190n opened this issue Feb 15, 2025 · 1 comment · May be fixed by #57069
Open

Calling clearImmediate on setTimeout return value can make future setTimeout callbacks never run #57063

190n opened this issue Feb 15, 2025 · 1 comment · May be fixed by #57069
Labels
timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout.

Comments

@190n
Copy link

190n commented Feb 15, 2025

Version

v23.3.0

Platform

Darwin mac.local 24.1.0 Darwin Kernel Version 24.1.0: Thu Oct 10 21:05:23 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6031 arm64

Subsystem

timers

What steps will reproduce the bug?

Run the following script:

const t = setTimeout(() => {
  console.log("1");
}, 0);
clearImmediate(t);
await new Promise(resolve =>
  setTimeout(() => {
    console.log("2");
    resolve();
  }, 0),
);
await new Promise(resolve =>
  setTimeout(() => {
    console.log("3");
    resolve();
  }, 0),
);

How often does it reproduce? Is there a required condition?

Reproduces every time

What is the expected behavior? Why is that the expected behavior?

2
3

The first timeout should be cleared, and the second two should run because they were not cleared.

What do you see instead?

The last setTimeout callback never runs:

$ node example.mjs
2
Warning: Detected unsettled top-level await at file:///Users/ben/example.mjs:11
await new Promise(resolve =>
^
$

Additional information

No response

@targos
Copy link
Member

targos commented Feb 15, 2025

@nodejs/timers

@targos targos added the timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout. label Feb 15, 2025
@gurgunday gurgunday linked a pull request Feb 15, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants