From 11259a06200146e3405c0e77e24d72ce1161b7fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D0=BB=D0=B5=D1=80=D0=B8=D0=B8=CC=86=20=D0=A1?= =?UTF-8?q?=D1=82=D0=B0=D0=B4=D1=87=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Sun, 28 Dec 2025 12:03:06 +0300 Subject: [PATCH] bugfixes --- ottomain.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/ottomain.go b/ottomain.go index 6a90e09..e79e353 100644 --- a/ottomain.go +++ b/ottomain.go @@ -111,29 +111,29 @@ func ProcessRequest(script string, params map[string]interface{}) (response map[ case vm.Interrupt <- func() { panic(errors.New("some code took to long! Stopping after timeout")) }: - // Interrupt sent successfully + // Interrupt sent case <-timeoutDone: - // Script completed before timeout, timer already stopped - return + // Script already completed } case <-timeoutDone: - // Script completed before timeout, stop timer - if !timeoutTimer.Stop() { - <-timeoutTimer.C + // Script completed before timeout, ensure timer is stopped + timeoutTimer.Stop() + // Drain timer channel if needed (non-blocking) + select { + case <-timeoutTimer.C: + default: } - return } }() defer func() { - // Signal timeout goroutine to exit and stop timer + // Signal timeout goroutine to exit by closing channel close(timeoutDone) - if !timeoutTimer.Stop() { - select { - case <-timeoutTimer.C: - default: - } - } + + // Stop timer - this is safe even if it already fired + // We don't need to drain the channel here as goroutine handles it + timeoutTimer.Stop() + if r := recover(); r != nil { switch x := r.(type) { case error: