GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — timers: refactor setImmediate error handling by apapirovski · Pull Request #17879 · nodejs/node

Conversation

@apapirovski

@apapirovski apapirovski commented Dec 27, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

If an error is encountered during the processing of Immediates, schedule the remaining queue to finish after all error handling code runs (if the process is still alive to do so). The new changes make the Immediates error handling behaviour entirely deterministic and predictable, as the full queue will be flushed on each Immediates cycle, regardless of whether an error is encountered or not.

Currently this processing is scheduled for nextTick which can yield unpredictable results as the nextTick might happen as early as close callbacks phase or as late as after the next event loop turns Immediates all fully process. The latter can result in two full cycles of Immediates processing during one event loop turn.

The current implementation also doesn't differentiate between Immediates scheduled for the current queue run or the next one, so Immediates that were scheduled for the next turn of the event loop, will process alongside the ones that were scheduled for the current turn.

It's possible this behaviour is semver-minor/semver-major although I would argue it's at worst semver-patch, as the current behaviour is entirely unpredictable and highly depends on what other operations are scheduled after the error handling is resolved.

CI: https://ci.nodejs.org/job/node-test-pull-request/12314/
CitGM: https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/1174/

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

src, timers, test

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

addaleax reacted with hooray emoji
All reactions
  • 🎉 1 reaction
@apapirovski apapirovski added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. timers Issues and PRs related to timers, setImmediate(), setInterval(), and setTimeout(). labels Dec 27, 2017
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. labels Dec 27, 2017
addaleax
addaleax requested changes Dec 27, 2017
View reviewed changes
Comment thread src/env.h Outdated

@addaleax addaleax Dec 27, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

From an initial look: It’s your call whether turning this into a class is helpful or not, but in any case the storage should only be accessed as an AliasedBuffer, since that is necessary for ChakraCore’s time-travel debugging to work with these values (because otherwise it can’t witness the changes from C++).

If you miss the availability of ++ and --, I guess it’s fair to add those to the AliasedBuffer reference class?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

apapirovski reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@apapirovski apapirovski Dec 27, 2017

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks, wasn't aware of that. Will make some changes.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@apapirovski
apapirovski force-pushed the patch-timers-immediate-error branch from fe84d67 to 7e2c037 Compare December 27, 2017 17:49
@apapirovski

apapirovski commented Dec 27, 2017

Copy link
Copy Markdown
Contributor Author

Ok, updated. PTAL @addaleax

CI: https://ci.nodejs.org/job/node-test-pull-request/12315/
CitGM: https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/1175/
Benchmark CI: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/80/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

addaleax
addaleax approved these changes Dec 27, 2017
View reviewed changes
Comment thread lib/timers.js Outdated

@addaleax addaleax Dec 27, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Optional: I would be specific and say “If an uncaught exception was thrown during execution …”

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/timers.js Outdated

@addaleax addaleax Dec 27, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Just making sure: These are a drive-by fix and not related to the exception handling itself, because domains use async hooks now anyway. Right?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@apapirovski apapirovski Dec 27, 2017

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Correct.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@apapirovski apapirovski Dec 27, 2017

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I'm actually thinking that this should be a separate PR because this change could be back-ported but the domain portion probably can't.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/timers.js Outdated

@addaleax addaleax Dec 27, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

It’s not really obvious that this is a 0/1 flag, so I’d prefer to have it called something like kHasOutstanding?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

apapirovski reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread src/env-inl.h Outdated

@addaleax addaleax Dec 27, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This could return a boolean too, I guess?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

apapirovski reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@apapirovski
apapirovski force-pushed the patch-timers-immediate-error branch 2 times, most recently from 0c72b4f to 52d65d8 Compare December 27, 2017 19:05
@apapirovski apapirovski added the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Dec 29, 2017
@apapirovski
apapirovski force-pushed the patch-timers-immediate-error branch from 52d65d8 to 6d58100 Compare January 2, 2018 13:12
@apapirovski
timers: refactor setImmediate error handling
3dd5c1b
If an error is encountered during the processing of Immediates, schedule
the remaining queue to finish after all error handling code runs (if the
process is still alive to do so). The new changes make the Immediates
error handling behaviour entirely deterministic and predictable, as the
full queue will be flushed on each Immediates cycle, regardless of
whether an error is encountered or not.

Currently this processing is scheduled for nextTick which can yield
unpredictable results as the nextTick might happen as early as close
callbacks phase or as late as after the next event loop turns Immediates
all fully processed. The latter can result in two full cycles of
Immediates processing during one even loop turn.

The current implementation also doesn't differentiate between Immediates
scheduled for the current queue run or the next one, so Immediates that
were scheduled for the next turn of the event loop, will process
alongside the ones that were scheduled for the current turn.
@apapirovski
apapirovski force-pushed the patch-timers-immediate-error branch from 6d58100 to 3dd5c1b Compare January 2, 2018 13:19
@apapirovski

apapirovski commented Jan 2, 2018

Copy link
Copy Markdown
Contributor Author

Rebased. CI: https://ci.nodejs.org/job/node-test-pull-request/12366/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jasnell
jasnell approved these changes Jan 2, 2018
View reviewed changes
@apapirovski

apapirovski commented Jan 2, 2018

Copy link
Copy Markdown
Contributor Author

Landed in 54062d3

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@apapirovski apapirovski closed this Jan 2, 2018
@apapirovski
apapirovski deleted the patch-timers-immediate-error branch January 2, 2018 16:17
apapirovski added a commit that referenced this pull request Jan 2, 2018
@apapirovski
timers: refactor setImmediate error handling
54062d3
If an error is encountered during the processing of Immediates, schedule
the remaining queue to finish after all error handling code runs (if the
process is still alive to do so). The new changes make the Immediates
error handling behaviour entirely deterministic and predictable, as the
full queue will be flushed on each Immediates cycle, regardless of
whether an error is encountered or not.

Currently this processing is scheduled for nextTick which can yield
unpredictable results as the nextTick might happen as early as close
callbacks phase or as late as after the next event loop turns Immediates
all fully processed. The latter can result in two full cycles of
Immediates processing during one even loop turn.

The current implementation also doesn't differentiate between Immediates
scheduled for the current queue run or the next one, so Immediates that
were scheduled for the next turn of the event loop, will process
alongside the ones that were scheduled for the current turn.

PR-URL: #17879
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@MylesBorins MylesBorins added the backported-to-v9.x label Jan 9, 2018
@MylesBorins

MylesBorins commented Jan 9, 2018

Copy link
Copy Markdown
Contributor

This does not land cleanly on v9.x, could it be manually backported?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@apapirovski apapirovski added backport-requested-v9.x and removed backported-to-v9.x labels Jan 10, 2018
@TimothyGu TimothyGu removed the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Jan 13, 2018
@apapirovski apapirovski mentioned this pull request Jan 31, 2018
[v9.x backport] 17738 and 17841 #18488
Closed
3 tasks done
apapirovski added a commit to apapirovski/node that referenced this pull request Feb 26, 2018
@apapirovski
timers: refactor setImmediate error handling
1d2592f
If an error is encountered during the processing of Immediates, schedule
the remaining queue to finish after all error handling code runs (if the
process is still alive to do so). The new changes make the Immediates
error handling behaviour entirely deterministic and predictable, as the
full queue will be flushed on each Immediates cycle, regardless of
whether an error is encountered or not.

Currently this processing is scheduled for nextTick which can yield
unpredictable results as the nextTick might happen as early as close
callbacks phase or as late as after the next event loop turns Immediates
all fully processed. The latter can result in two full cycles of
Immediates processing during one even loop turn.

The current implementation also doesn't differentiate between Immediates
scheduled for the current queue run or the next one, so Immediates that
were scheduled for the next turn of the event loop, will process
alongside the ones that were scheduled for the current turn.

PR-URL: nodejs#17879
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
addaleax pushed a commit that referenced this pull request Feb 26, 2018
@apapirovski @addaleax
timers: refactor setImmediate error handling
d2475cc
If an error is encountered during the processing of Immediates, schedule
the remaining queue to finish after all error handling code runs (if the
process is still alive to do so). The new changes make the Immediates
error handling behaviour entirely deterministic and predictable, as the
full queue will be flushed on each Immediates cycle, regardless of
whether an error is encountered or not.

Currently this processing is scheduled for nextTick which can yield
unpredictable results as the nextTick might happen as early as close
callbacks phase or as late as after the next event loop turns Immediates
all fully processed. The latter can result in two full cycles of
Immediates processing during one even loop turn.

The current implementation also doesn't differentiate between Immediates
scheduled for the current queue run or the next one, so Immediates that
were scheduled for the next turn of the event loop, will process
alongside the ones that were scheduled for the current turn.

Backport-PR-URL: #19006
PR-URL: #17879
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@addaleax addaleax added backported-to-v9.x and removed backport-requested-v9.x labels Feb 26, 2018
addaleax pushed a commit that referenced this pull request Feb 26, 2018
@apapirovski @addaleax
timers: refactor setImmediate error handling
01ef0f1
If an error is encountered during the processing of Immediates, schedule
the remaining queue to finish after all error handling code runs (if the
process is still alive to do so). The new changes make the Immediates
error handling behaviour entirely deterministic and predictable, as the
full queue will be flushed on each Immediates cycle, regardless of
whether an error is encountered or not.

Currently this processing is scheduled for nextTick which can yield
unpredictable results as the nextTick might happen as early as close
callbacks phase or as late as after the next event loop turns Immediates
all fully processed. The latter can result in two full cycles of
Immediates processing during one even loop turn.

The current implementation also doesn't differentiate between Immediates
scheduled for the current queue run or the next one, so Immediates that
were scheduled for the next turn of the event loop, will process
alongside the ones that were scheduled for the current turn.

Backport-PR-URL: #19006
PR-URL: #17879
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this pull request Feb 26, 2018
@apapirovski @MylesBorins
timers: refactor setImmediate error handling
37f253e
If an error is encountered during the processing of Immediates, schedule
the remaining queue to finish after all error handling code runs (if the
process is still alive to do so). The new changes make the Immediates
error handling behaviour entirely deterministic and predictable, as the
full queue will be flushed on each Immediates cycle, regardless of
whether an error is encountered or not.

Currently this processing is scheduled for nextTick which can yield
unpredictable results as the nextTick might happen as early as close
callbacks phase or as late as after the next event loop turns Immediates
all fully processed. The latter can result in two full cycles of
Immediates processing during one even loop turn.

The current implementation also doesn't differentiate between Immediates
scheduled for the current queue run or the next one, so Immediates that
were scheduled for the next turn of the event loop, will process
alongside the ones that were scheduled for the current turn.

Backport-PR-URL: #19006
PR-URL: #17879
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@addaleax addaleax mentioned this pull request Feb 27, 2018
v9.7.0 proposal #19040
Closed
@MylesBorins

MylesBorins commented Jul 31, 2018

Copy link
Copy Markdown
Contributor

Should this be backported to v8.x-staging? If yes please follow the guide and raise a backport PR, if not let me know or add the dont-land-on label.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@MylesBorins MylesBorins added the backport-requested-v8.x label Jul 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@jasnell jasnell jasnell approved these changes
@addaleax addaleax addaleax approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. timers Issues and PRs related to timers, setImmediate(), setInterval(), and setTimeout().

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@apapirovski @MylesBorins @jasnell @addaleax @TimothyGu @nodejs-github-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.