From e8440a0b2e08cb0b82611f3fa8e49b77ca84ce47 Mon Sep 17 00:00:00 2001 From: ankur22 Date: Fri, 5 Apr 2024 17:09:48 +0100 Subject: [PATCH] Add fix to prevent panic when ctx closed If the context is closed, and that is the error that is received by the dispose method, then that would elude to the fact that the iteration has ended. Therefore, we shouldn't need to panic or log an error at this point, and instead just continue on as normal. The page has closed well before this panic occurs. --- common/js_handle.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/common/js_handle.go b/common/js_handle.go index f551c0feb..86cd291b0 100644 --- a/common/js_handle.go +++ b/common/js_handle.go @@ -2,6 +2,7 @@ package common import ( "context" + "errors" "fmt" "github.com/grafana/xk6-browser/k6ext" @@ -81,6 +82,10 @@ func (h *BaseJSHandle) AsElement() *ElementHandle { func (h *BaseJSHandle) Dispose() { fmt.Println(">>>>>>: BaseJSHandler Dispose") if err := h.dispose(); err != nil { + if errors.Is(err, context.Canceled) { + fmt.Println(">>>>>>: Skipping context canceled error on Dispose", err) + return + } fmt.Println(">>>>>>: BaseJSHandler Dispose error", err) k6ext.Panic(h.ctx, "dispose: %w", err) }