From c93697f49150431aa05265b936f69fdef5534cef Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Wed, 30 Oct 2024 19:24:47 +0100 Subject: [PATCH] runtime: don't call sleepTicks with a negative duration There are rare cases where this can happen, see for example https://github.com/tinygo-org/tinygo/issues/4568 --- src/runtime/scheduler.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/runtime/scheduler.go b/src/runtime/scheduler.go index 3f726a0641..203e954c36 100644 --- a/src/runtime/scheduler.go +++ b/src/runtime/scheduler.go @@ -230,13 +230,15 @@ func scheduler(returnAtDeadlock bool) { println("--- timer waiting:", tim, tim.whenTicks()) } } - sleepTicks(timeLeft) - if asyncScheduler { - // The sleepTicks function above only sets a timeout at which - // point the scheduler will be called again. It does not really - // sleep. So instead of sleeping, we return and expect to be - // called again. - break + if timeLeft > 0 { + sleepTicks(timeLeft) + if asyncScheduler { + // The sleepTicks function above only sets a timeout at + // which point the scheduler will be called again. It does + // not really sleep. So instead of sleeping, we return and + // expect to be called again. + break + } } continue }