From c0329caa5452a873b4f42f6f2b535be446034307 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: Fri, 26 Dec 2025 16:08:14 +0300 Subject: [PATCH] fix --- ottomain.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/ottomain.go b/ottomain.go index 8765d6d..995ee18 100644 --- a/ottomain.go +++ b/ottomain.go @@ -62,14 +62,27 @@ func ProcessRequest(script string, params map[string]interface{}) (response map[ } vm.Interrupt = make(chan func(), 1) + timeoutDone := make(chan struct{}) + go func() { - time.Sleep(time.Duration(cfg.Timeout) * time.Second) - vm.Interrupt <- func() { - panic(errors.New("some code took to long! Stopping after timeout")) + select { + case <-time.After(time.Duration(cfg.Timeout) * time.Second): + select { + case vm.Interrupt <- func() { + panic(errors.New("some code took to long! Stopping after timeout")) + }: + case <-timeoutDone: + // Script completed before timeout, exit gracefully + return + } + case <-timeoutDone: + // Script completed before timeout, exit gracefully + return } }() defer func() { + close(timeoutDone) // Signal timeout goroutine to exit if r := recover(); r != nil { switch x := r.(type) { case error: