1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-11 08:33:43 -05:00

js: reschedule global timer if it fires earlier than expected (#2989)

When the global timer fires earlier than expected, which apparently
happens sometimes on server editions of Windows, we didn't call any
setTimeout callbacks, but we *also* didn't reschedule the global timer
to fire again later.

When this situation occurred it would make deno exit abruptly if there
were no other asynchronous ops running on the event loop. It could also
lead to application hangs if the upcoming setTimeout callback was
critical for the application to make progress.
This commit is contained in:
Bert Belder 2019-09-20 00:09:43 +02:00
parent 560edc536c
commit 93b7acf99d
No known key found for this signature in database
GPG key ID: 7A77887B2E2ED461
2 changed files with 3 additions and 3 deletions

View file

@ -33,7 +33,7 @@ pub fn op_global_timer(
let state = state;
let mut t = state.global_timer.lock().unwrap();
let deadline = Instant::now() + Duration::from_millis(val as u64);
let deadline = Instant::now() + Duration::from_millis(val);
let f = t
.new_timeout(deadline)
.then(move |_| futures::future::ok(json!({})));

View file

@ -138,8 +138,8 @@ function fire(timer: Timer): void {
function fireTimers(): void {
const now = getTime();
// Bail out if we're not expecting the global timer to fire (yet).
if (globalTimeoutDue === null || now < globalTimeoutDue) {
// Bail out if we're not expecting the global timer to fire.
if (globalTimeoutDue === null) {
return;
}
// After firing the timers that are due now, this will hold the due time of