New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 722410 link

Starred by 1 user

Issue metadata

Status: Fixed
Owner:
Closed: Jun 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 1
Type: Bug-Regression



Sign in to add a comment

setInterval stops when window goes out of focus

Reported by ayy...@gmail.com, May 15 2017

Issue description

UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3100.0 Safari/537.36

Steps to reproduce the problem:
1. Code: setInterval to count down 
2. Trigger the counter
3. Open a new tab
4. Come back after few minutes, the counter changed, but not as expected

Used this code on both Chrome and Canary, focusing on a different tab does not affect count down on Chrome, but on Canary it definitely goes much slower
<button id="b">start</button>
	<div id="s"></div>
	<script>
		var _timer, x = 60;
		var b = document.getElementById('b');
		b.onclick = function doTimer() {
			var s = document.getElementById('s');

		_timer = window.setInterval(function () {

			s.innerText = x--;
			x == 0 && (window.clearInterval(_timer));
			}, 1000);
		};
	</script>

What is the expected behavior?
The countdown should continue even if on another tab.

What went wrong?
setInterval should continue to fire even if tab loses focus.

Did this work before? Yes Chrome  58.0.3029.110 (64-bit)

Chrome version: 60.0.3100.0  Channel: canary
OS Version: 10.0
Flash Version: 

Code works on Chrome, and it works if there are no other tabs open, even if the browser window loses focus. Not sure what Canary version it stopped working.
Might be related to Issue 679763
 
Cc: ligim...@chromium.org
Labels: Needs-Bisect Needs-Triage-M58
Cc: kavvaru@chromium.org
Labels: Needs-Feedback
Could you please provide us any sample test file or URL to triage the issue from test team end.

Thanks,
Cc: altimin@chromium.org
Status: Available (was: Unconfirmed)
How does the counter value actually change in your experiment? Ideally it should tick down once a second, right?

I think this might be caused by CPU budget throttling and is in that sense expected behavior: https://www.chromestatus.com/features/6172836527865856
Components: -Blink Blink>Scheduling

Comment 5 by ayy...@gmail.com, May 16 2017

here is a test page
http://vinepaper.com/timeout.html
when I did side by side test on chrome and canary, the difference in the count down towards the end of one minute was about 15 seconds... there is nothing else keeping the browser busy. This is a very important feature as we need to count down the time the user can reserve a ticket, it isn't server based, but it does give feedback to the user. Don't know if I have other alternatives, are there?
Labels: -Pri-2 Pri-1
Thank you for the bug report. I can reproduce the behaviour in Chrome Dev 60.0.3095.5. This is probably wrong and should be fixed.

But please note that the usage of timers in background is discouraged. We (and the spec) can't guarantee that the task will run at the desired time due to a number of factors (other javascript tasks, high system load level, etc) and we intentionally won't do it to preserve user's battery: we have a number of heuristics in place to delay timers in the background if we think that they are expensive.

The recommendation here is to stop relying on setInterval being called at regular intervals and check for the real time instead (it's better to use window.performance.now() as it is monotonic and is unaffected by system time changes).
Owner: altimin@chromium.org
Status: Started (was: Available)
It looks like the setInterval is throttled to 2 second interval instead of 1 second interval.

Seems that my new throttling mechanisms do not play nicely with setInterval.
Two other things to learn from here:
- Tests! We have decent coverage for setTimeout, but not setInterval.
- --disable-background-timer-throttling seems broken at the moment. Should we add a test?


Filed  crbug.com/722891  to track --disable-background-timer-throttling work.
Labels: -OS-Windows -Needs-Feedback -Arch-x86_64 -Needs-Bisect -Needs-Triage-M58 Arch-All OS-All
Update: setTimeout seems affected by this too.

So, essentially, we increased effective throttling frequency from 1Hz to 0.5Hz. I'm very surprised that we don't have a lot of failures in the tests.

My speculation is that it is due to our unittests having frozen(-ish) time, where it advances only after a task has been completed. We might want to consider unittests where each call to TestTimeClock::Now advances it by 1 microsecond to represent natural passage of time and iron out some corner cases.
Project Member

Comment 10 by bugdroid1@chromium.org, May 22 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/188fc72030f13187af5cff7e9802f3abebdea017

commit 188fc72030f13187af5cff7e9802f3abebdea017
Author: altimin <altimin@chromium.org>
Date: Mon May 22 17:17:43 2017

[scheduler] Move task alignment into WakeUpBudgetPool.

This fixes the regression where real-world throttling regressed to
two-seconds task alignment instead of one-second alignment.
This patch also improves test coverage for background throttling.

BUG= 722410 

Review-Url: https://codereview.chromium.org/2896603002
Cr-Commit-Position: refs/heads/master@{#473609}

[modify] https://crrev.com/188fc72030f13187af5cff7e9802f3abebdea017/third_party/WebKit/Source/platform/scheduler/renderer/budget_pool_unittest.cc
[modify] https://crrev.com/188fc72030f13187af5cff7e9802f3abebdea017/third_party/WebKit/Source/platform/scheduler/renderer/task_queue_throttler.cc
[modify] https://crrev.com/188fc72030f13187af5cff7e9802f3abebdea017/third_party/WebKit/Source/platform/scheduler/renderer/task_queue_throttler.h
[modify] https://crrev.com/188fc72030f13187af5cff7e9802f3abebdea017/third_party/WebKit/Source/platform/scheduler/renderer/task_queue_throttler_unittest.cc
[modify] https://crrev.com/188fc72030f13187af5cff7e9802f3abebdea017/third_party/WebKit/Source/platform/scheduler/renderer/wake_up_budget_pool.cc
[modify] https://crrev.com/188fc72030f13187af5cff7e9802f3abebdea017/third_party/WebKit/Source/platform/scheduler/renderer/wake_up_budget_pool.h
[modify] https://crrev.com/188fc72030f13187af5cff7e9802f3abebdea017/third_party/WebKit/Source/web/tests/scheduler/ThrottlingTest.cpp

Project Member

Comment 11 by bugdroid1@chromium.org, May 22 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/8e701ae2e5e345d6938c566dc4b9d6ac7c397b20

commit 8e701ae2e5e345d6938c566dc4b9d6ac7c397b20
Author: mek <mek@chromium.org>
Date: Mon May 22 17:50:53 2017

Revert of [scheduler] Move task alignment into WakeUpBudgetPool. (patchset #5 id:80001 of https://codereview.chromium.org/2896603002/ )

Reason for revert:
Regresses sizes on https://build.chromium.org/p/chromium/buildstatus?builder=Linux%20x64&number=40173 (due to include of iostream)

Original issue's description:
> [scheduler] Move task alignment into WakeUpBudgetPool.
>
> This fixes the regression where real-world throttling regressed to
> two-seconds task alignment instead of one-second alignment.
> This patch also improves test coverage for background throttling.
>
> BUG= 722410 
>
> Review-Url: https://codereview.chromium.org/2896603002
> Cr-Commit-Position: refs/heads/master@{#473609}
> Committed: https://chromium.googlesource.com/chromium/src/+/188fc72030f13187af5cff7e9802f3abebdea017

TBR=skyostil@chromium.org,alexclarke@chromium.org,altimin@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG= 722410 

Review-Url: https://codereview.chromium.org/2893363002
Cr-Commit-Position: refs/heads/master@{#473615}

[modify] https://crrev.com/8e701ae2e5e345d6938c566dc4b9d6ac7c397b20/third_party/WebKit/Source/platform/scheduler/renderer/budget_pool_unittest.cc
[modify] https://crrev.com/8e701ae2e5e345d6938c566dc4b9d6ac7c397b20/third_party/WebKit/Source/platform/scheduler/renderer/task_queue_throttler.cc
[modify] https://crrev.com/8e701ae2e5e345d6938c566dc4b9d6ac7c397b20/third_party/WebKit/Source/platform/scheduler/renderer/task_queue_throttler.h
[modify] https://crrev.com/8e701ae2e5e345d6938c566dc4b9d6ac7c397b20/third_party/WebKit/Source/platform/scheduler/renderer/task_queue_throttler_unittest.cc
[modify] https://crrev.com/8e701ae2e5e345d6938c566dc4b9d6ac7c397b20/third_party/WebKit/Source/platform/scheduler/renderer/wake_up_budget_pool.cc
[modify] https://crrev.com/8e701ae2e5e345d6938c566dc4b9d6ac7c397b20/third_party/WebKit/Source/platform/scheduler/renderer/wake_up_budget_pool.h
[modify] https://crrev.com/8e701ae2e5e345d6938c566dc4b9d6ac7c397b20/third_party/WebKit/Source/web/tests/scheduler/ThrottlingTest.cpp

Project Member

Comment 12 by bugdroid1@chromium.org, May 23 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/c37e844a6f87088261bf3c595ea34b64b15f1633

commit c37e844a6f87088261bf3c595ea34b64b15f1633
Author: altimin <altimin@chromium.org>
Date: Tue May 23 12:30:35 2017

[scheduler] Move task alignment into WakeUpBudgetPool.

This fixes the regression where real-world throttling regressed to
two-seconds task alignment instead of one-second alignment.
This patch also improves test coverage for background throttling.

BUG= 722410 

Review-Url: https://codereview.chromium.org/2896603002
Cr-Original-Commit-Position: refs/heads/master@{#473609}
Committed: https://chromium.googlesource.com/chromium/src/+/188fc72030f13187af5cff7e9802f3abebdea017
Review-Url: https://codereview.chromium.org/2896603002
Cr-Commit-Position: refs/heads/master@{#473867}

[modify] https://crrev.com/c37e844a6f87088261bf3c595ea34b64b15f1633/third_party/WebKit/Source/platform/scheduler/renderer/budget_pool_unittest.cc
[modify] https://crrev.com/c37e844a6f87088261bf3c595ea34b64b15f1633/third_party/WebKit/Source/platform/scheduler/renderer/task_queue_throttler.cc
[modify] https://crrev.com/c37e844a6f87088261bf3c595ea34b64b15f1633/third_party/WebKit/Source/platform/scheduler/renderer/task_queue_throttler.h
[modify] https://crrev.com/c37e844a6f87088261bf3c595ea34b64b15f1633/third_party/WebKit/Source/platform/scheduler/renderer/task_queue_throttler_unittest.cc
[modify] https://crrev.com/c37e844a6f87088261bf3c595ea34b64b15f1633/third_party/WebKit/Source/platform/scheduler/renderer/wake_up_budget_pool.cc
[modify] https://crrev.com/c37e844a6f87088261bf3c595ea34b64b15f1633/third_party/WebKit/Source/platform/scheduler/renderer/wake_up_budget_pool.h
[modify] https://crrev.com/c37e844a6f87088261bf3c595ea34b64b15f1633/third_party/WebKit/Source/web/tests/scheduler/ThrottlingTest.cpp

Status: Fixed (was: Started)

Sign in to add a comment