Skip to content
This repository has been archived by the owner on Aug 31, 2018. It is now read-only.

timers: warn on overflowed timeout duration #71

Closed

Conversation

Fishrock123
Copy link
Contributor

Previously there wasn't any clear indicator when you hit the overflow
other than possibly unexpected behavior, and I think emitting a warning
may be appropriate.

While it may be viable to allow the use of 64bit numbers in enroll(), browser setTimeout/setInterval just coerces it to 1, which we've been roughly following so far.

I previously had a PR for this at nodejs/node#6956 but I didn't really take it anywhere at the time.

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)

timers

@hypesystem
Copy link

hypesystem commented Sep 19, 2017

Could you explain what you mean about "hitting the overflow"? I'm a bit confused by it.

Edit: as I understand the code, it means if a timeout or interval is given a number higher than the mac allowrd (32bit int?). It makes sense to warn when this happens, imo. But why does the limit exist?

Edit2: also, it seems that rn it is coerced to TIMEOUT_MAX, instead of 1 as in browsers (per your original message)?

Copy link
Contributor

@addaleax addaleax left a comment

Choose a reason for hiding this comment

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

Looks good to me, but yeah, I wonder, what keeps us from supporting longer timeouts? libuv seems to support them?

@Fishrock123
Copy link
Contributor Author

Fishrock123 commented Sep 19, 2017

@hypesystem see

ayo/lib/timers.js

Lines 46 to 47 in edc403c

// Timeout values > TIMEOUT_MAX are set to 1.
const TIMEOUT_MAX = 2147483647; // 2^31-1

When a timer's duration is longer than that.


@addaleax in the OP:

While it may be viable to allow the use of 64bit numbers in enroll(), browser setTimeout/setInterval just coerces it to 1, which we've been roughly following so far.

@hypesystem
Copy link

@Fishrock123 realized I was a bit quick. Updated the original comment with better questions 😄

@Fishrock123
Copy link
Contributor Author

Fishrock123 commented Sep 19, 2017

Edit2: also, it seems that rn it is coerced to TIMEOUT_MAX, instead of 1 as in browsers (per your original message)?

enroll() is usable separately from set{Timeout|Interval}(), which is where that particular line of code is from.

@BridgeAR
Copy link
Contributor

@Fishrock123 why is the browser behavior the best though? Is it really necessary to follow that? I think it would be best to just increase the maximum instead.

@jasnell
Copy link
Contributor

jasnell commented Sep 20, 2017

Is there any particular reason that nodejs/node#6956 wasn't pursued? It seemed like a reasonable change.

edited by @TimothyGu to fix link

@Fishrock123
Copy link
Contributor Author

why is the browser behavior the best though? Is it really necessary to follow that? I think it would be best to just increase the maximum instead.

Best? Not really.
Necessary to follow? Unsure, but that has been the historical precedent.

Consider that the maximum using 32 bits is already some ~26 days or so in length.


Is there any particular reason that nodejs/node#6956 wasn't pursued? It seemed like a reasonable change.

At the time, time&energy. Now-ish? Wanted to see how PRing to Ayo will be like. Also a part of me would kinda like to deal with less potential edge-case nonsense fallout since historically people just yell more when there are warnings, useful or not. ¯\_(ツ)_/¯

@Fishrock123 Fishrock123 force-pushed the ayo-warn-on-timeout-overflow branch from b17d7b6 to 2045a3d Compare September 20, 2017 15:10
Fishrock123 added a commit to Fishrock123/ayo that referenced this pull request Sep 20, 2017
Previously there wasn't any clear indicator when you hit the overflow
other than possibly unexpected behavior, and I think emitting a warning
may be appropriate.

PR-URL: ayojs#71
@Fishrock123
Copy link
Contributor Author

It appears the linter run from travis didn't catch some long lines? Any idea why @addaleax?

@addaleax
Copy link
Contributor

heh … I don’t think Travis is actually running the linter – my bad, sorry!

@@ -538,8 +548,15 @@ exports.setInterval = function(callback, repeat, arg1, arg2, arg3) {

function createRepeatTimeout(callback, repeat, args) {
repeat *= 1; // coalesce to number or NaN
if (!(repeat >= 1 && repeat <= TIMEOUT_MAX))
if (!(repeat >= 1 && repeat <= TIMEOUT_MAX)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it feasible to avoid duplicating code in createSingleTimeout() and createRepeatTimeout()?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is the emitWarning call the duplicate code you're referring to?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The warning message differs slightly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, that's what I was going to say. Doesn't seem worth abstracting, IMO.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup, sorry, didn't notice the difference in warning messages.


const OVERFLOW = Math.pow(2, 31); // TIMEOUT_MAX is 2^31-1

function TimerNotCanceled() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd say this function's name should start with a lowercase letter.

Fishrock123 added a commit to Fishrock123/node that referenced this pull request Sep 20, 2017
It's be nice to have it run as a separate task, but I think this should
work for now.

Refs: ayojs/ayo#71
Fishrock123 added a commit to Fishrock123/ayo that referenced this pull request Sep 20, 2017
It'd be nice to have it run as a separate task, but I think this should
work for now.

Refs: ayojs#71
Fishrock123 added a commit to Fishrock123/ayo that referenced this pull request Sep 21, 2017
Fishrock123 added a commit to Fishrock123/ayo that referenced this pull request Sep 21, 2017
Previously there wasn't any clear indicator when you hit the overflow
other than possibly unexpected behavior, and I think emitting a warning
may be appropriate.

PR-URL: ayojs#71
@Fishrock123 Fishrock123 force-pushed the ayo-warn-on-timeout-overflow branch from 2045a3d to 7d216e4 Compare September 21, 2017 16:19
Fishrock123 added a commit to Fishrock123/ayo that referenced this pull request Sep 21, 2017
Divides the CI jobs by a custom `matrix:`, with a new linter job
using an existing node.js binary to run `make lint-ci` (eslint).

Refs: ayojs#71
addaleax pushed a commit that referenced this pull request Sep 25, 2017
Divides the CI jobs by a custom `matrix:`, with a new linter job
using an existing node.js binary to run `make lint-ci` (eslint).

Refs: #71
PR-URL: #75
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@Fishrock123
Copy link
Contributor Author

I suppose this should be land-able if it is something ya'll think would be good?

Fishrock123 added a commit to Fishrock123/node that referenced this pull request Sep 26, 2017
Previously there wasn't any clear indicator when you hit the overflow
other than possibly unexpected behavior, and I think emitting a warning
may be appropriate.

PR-URL: ayojs/ayo#71
@Qard
Copy link
Member

Qard commented Sep 26, 2017

Yeah, seems reasonable to me.

addaleax pushed a commit that referenced this pull request Sep 26, 2017
Previously there wasn't any clear indicator when you hit the overflow
other than possibly unexpected behavior, and I think emitting a warning
may be appropriate.

PR-URL: #71
Reviewed-By: Scott Trinh <scott@scotttrinh.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
@addaleax
Copy link
Contributor

@Fishrock123 yup, thanks for the ping!

Landed in 607316c!

@addaleax addaleax closed this Sep 26, 2017
jasnell pushed a commit to jasnell/node that referenced this pull request Sep 26, 2017
Cherry-pick from ayo

Ayo commit log:
> Previously there wasn't any clear indicator when you hit the overflow
> other than possibly unexpected behavior, and I think emitting a warning
> may be appropriate.

> PR-URL: ayojs/ayo#71
> Reviewed-By: Scott Trinh <scott@scotttrinh.com>
> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
> Reviewed-By: Anna Henningsen <anna@addaleax.net>
> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
jasnell pushed a commit to nodejs/node that referenced this pull request Sep 29, 2017
Cherry-pick from ayo

Ayo commit log:
> Previously there wasn't any clear indicator when you hit the overflow
> other than possibly unexpected behavior, and I think emitting a warning
> may be appropriate.

> PR-URL: ayojs/ayo#71
> Reviewed-By: Scott Trinh <scott@scotttrinh.com>
> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
> Reviewed-By: Anna Henningsen <anna@addaleax.net>
> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>

PR-URL: #15627
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
MylesBorins pushed a commit to nodejs/node that referenced this pull request Sep 29, 2017
Cherry-pick from ayo

Ayo commit log:
> Previously there wasn't any clear indicator when you hit the overflow
> other than possibly unexpected behavior, and I think emitting a warning
> may be appropriate.

> PR-URL: ayojs/ayo#71
> Reviewed-By: Scott Trinh <scott@scotttrinh.com>
> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
> Reviewed-By: Anna Henningsen <anna@addaleax.net>
> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>

PR-URL: #15627
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
MylesBorins pushed a commit to nodejs/node that referenced this pull request Oct 3, 2017
Cherry-pick from ayo

Ayo commit log:
> Previously there wasn't any clear indicator when you hit the overflow
> other than possibly unexpected behavior, and I think emitting a warning
> may be appropriate.

> PR-URL: ayojs/ayo#71
> Reviewed-By: Scott Trinh <scott@scotttrinh.com>
> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
> Reviewed-By: Anna Henningsen <anna@addaleax.net>
> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>

PR-URL: #15627
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
MylesBorins pushed a commit to nodejs/node that referenced this pull request Oct 3, 2017
Cherry-pick from ayo

Ayo commit log:
> Previously there wasn't any clear indicator when you hit the overflow
> other than possibly unexpected behavior, and I think emitting a warning
> may be appropriate.

> PR-URL: ayojs/ayo#71
> Reviewed-By: Scott Trinh <scott@scotttrinh.com>
> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
> Reviewed-By: Anna Henningsen <anna@addaleax.net>
> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>

PR-URL: #15627
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants