New issue
Advanced search Search tips

Issue 689947 link

Starred by 3 users

Issue metadata

Status: WontFix
Owner:
Closed: Feb 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Mac
Pri: 1
Type: Bug-Regression



Sign in to add a comment

setInterval running immediately when interval time is big

Reported by m...@bnaya.net, Feb 8 2017

Issue description

UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36

Steps to reproduce the problem:
Run this code on the console and see:
window.setInterval(() => {
debugger;
}, 1000);
window.setInterval(() => {
debugger;
}, 2592000000);

What is the expected behavior?
The second interval need to run every 2592000000 ms

What went wrong?
The second interval is  running every 0 ms

Did this work before? Yes 

Does this work in other browsers? N/A

Chrome version: 56.0.2924.87  Channel: stable
OS Version: OS X 10.12.3
Flash Version:

 

Comment 1 by woxxom@gmail.com, Feb 8 2017

The behavior you observe is correct because setInterval uses signed 32-bit values.
2147483647 is the maximum value as per specification, see [1]
2592000000 in your code exceeds that maximum and gets converted to a negative value, which is invalid so 0 is used instead.

  [1]: https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval

Comment 2 by woxxom@gmail.com, Feb 8 2017

On the other hand, I agree that conversion could be smarter and clamp the invalid values to the maximum value of 2147483647 and emit a warning in console.
Labels: Pri-1
****Bulk Edit****

Setting as P1 for test team to prioritize in triaging.
Labels: Needs-Triage-M56
Cc: rbasuvula@chromium.org
Labels: Needs-Feedback
Tested in chrome #56.0.2924.87 and Canary #58.0.3006.0 on Mac 10.12.2 and not able to reproduce the issue.Please find the screen shot for your reference.

@reporter: Could you please let me know if i have missed anything and if possible, provide us with a sample steps of the issue which would help us to triage the issue further.

Thanks in Advance.
689947.png
226 KB View Download
Components: Blink>Scheduling
Owner: delph...@chromium.org
Status: Assigned (was: Unconfirmed)
It's not actually running every 0ms.

  var t = window.performance.now();
  var count = 0;
  var id = window.setInterval(() => {
    if (++count > 7) {
      window.clearInterval(id);
    }
    t2 = window.performance.now();
    console.log(t2 - t);
    t = t2;
  }, 2592000000);

This code produces:

1.3500000000349246
0.8449999999720603
1
1.0249999999650754
3.9700000000884756
4.009999999951106
4.039999999979045
3.995000000053551

That's approximately {1, 1, 1, 1, 4, 4, 4, 4}, which is what you would expect if you'd used an interval of <1 since it clamps to 1ms for the first iterations and then after 4 iterations it clamps to 4ms.
The current behaviour is exactly what we would expect from the spec (and is also what we see in other browsers): https://html.spec.whatwg.org/multipage/webappapis.html#windoworworkerglobalscope-mixin:dom-setinterval

The timeout is defined as a long, which is defined as an Int32. No clamping is specified so normal conversion is performed which truncates and then returns the value modulo 2^31.

To introduce clamping we'd have to change the spec to add [Clamp] to the definition of setInterval (and setTimeout). I don't see the value since this would only affect someone who actually wanted an interval of 25+ days, who presumably would want the timeout to be exact rather than arbitrarily clamped.
Status: WontFix (was: Assigned)

Sign in to add a comment