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

setImmediate regression in v6.8.0 #9084

Closed
Fishrock123 opened this issue Oct 13, 2016 · 8 comments
Closed

setImmediate regression in v6.8.0 #9084

Fishrock123 opened this issue Oct 13, 2016 · 8 comments
Labels
confirmed-bug Issues with confirmed bugs. timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout.

Comments

@Fishrock123
Copy link
Contributor

Fishrock123 commented Oct 13, 2016

  • Version: v6.8.0
  • Platform: ?
  • Subsystem: timers

See: TryGhost/Ghost#7555
Moving from: #8655 (comment)

Regression from timers: improve setImmediate() performance (#8655)

Hey there!

We started having test failures due to this change. There's more information on the issue & PR linked just above this comment. To pull some of that here:

The last job never get's executed, because setImmediate does not get triggered!

We have a temporary fix in place in the PR, that reduces the timeout and this appears to work (the tests pass). Would love a little bit of input into how this change has impacted the functionality and whether we've found a bug or are doing something wrong :)

var jobs = [Date.now() + 1000, Date.now() + 2000, Date.now() + 3000];

jobs.forEach(function(timestamp) {
    var timeout = setTimeout(function() {
        clearTimeout(timeout);

        (function retry() {
            var immediate = setImmediate(function() {
                clearImmediate(immediate);

                if (Date.now() < timestamp) {
                    return retry();
                }

                console.log("FINISHED JOB");
            });
        }());
    }, timestamp - 200);
});

v6.8.0 - does not work, you will see 1 x FINISHED JOB
v4.4.7 && v6.7.0 - works as expected, you will see 3 x FINISHED JOB

cc @ErisDS, @thealphanerd, @mscdex, @Trott, @kirrg001

@Fishrock123 Fishrock123 added the timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout. label Oct 13, 2016
@Fishrock123 Fishrock123 changed the title SetImmediate regression in v6.8.0 setImmediate regression in v6.8.0 Oct 13, 2016
@Fishrock123 Fishrock123 added the confirmed-bug Issues with confirmed bugs. label Oct 13, 2016
@jbergstroem
Copy link
Member

CC reviewers: @jasnell, @imyller.

@Fishrock123
Copy link
Contributor Author

Smells like a problem with the new linkedlist bits but I'm having a hard time pinpointing it from the diff.

@targos
Copy link
Member

targos commented Oct 13, 2016

Hint: it works correctly if the clearImmediate(immediate); line is removed.

@Trott
Copy link
Member

Trott commented Oct 13, 2016

This looks like it could be related to the re-ordering of timers and immediates.

Take this code:

setTimeout(() => {console.log('foo')}, 1);
setImmediate(() => {console.log('bar')});
setTimeout(() => {console.log('foo')}, 1);
setImmediate(() => {console.log('bar')});

In 6.7.0, it usually (but not always!) returns:

bar
bar
foo
foo

But in 6.8.0, it usually (but not always!) returns:

foo
foo
bar
bar

@Trott
Copy link
Member

Trott commented Oct 13, 2016

Docs say setImmediate() should fire before timers, so if I'm understanding correctly, the typical results in 6.8.0 are a bug, albeit a bug that sometimes shows up in 6.7.0?

"if I'm understanding correctly" may be a big assumption here...

@jasnell
Copy link
Member

jasnell commented Oct 13, 2016

Let's revert the change and pinpoint the issue after.

@mscdex
Copy link
Contributor

mscdex commented Oct 13, 2016

I have a fix coming shortly.

@mscdex
Copy link
Contributor

mscdex commented Oct 13, 2016

Proposed fix: #9086

mscdex added a commit to mscdex/io.js that referenced this issue Oct 13, 2016
This commit fixes a regression introduced in 0ed8839 that caused
additional queued immediate callbacks to be ignored if
`clearImmediate(immediate)` was called within the callback for
`immediate`.

Fixes: nodejs#9084
evanlucas pushed a commit that referenced this issue Oct 14, 2016
This commit fixes a regression introduced in 0ed8839 that caused
additional queued immediate callbacks to be ignored if
`clearImmediate(immediate)` was called within the callback for
`immediate`.

PR-URL: #9086
Fixes: #9084
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
evanlucas pushed a commit that referenced this issue Oct 14, 2016
This commit fixes a regression introduced in 0ed8839 that caused
additional queued immediate callbacks to be ignored if
`clearImmediate(immediate)` was called within the callback for
`immediate`.

PR-URL: #9086
Fixes: #9084
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
jasnell pushed a commit that referenced this issue Oct 17, 2016
This commit fixes a regression introduced in 0ed8839 that caused
additional queued immediate callbacks to be ignored if
`clearImmediate(immediate)` was called within the callback for
`immediate`.

PR-URL: #9086
Fixes: #9084
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. 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.

6 participants