Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit f2817ff

Browse files
committed
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.
1 parent 41fe79b commit f2817ff

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

common/js_handle.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package common
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67

78
"github.com/grafana/xk6-browser/k6ext"
@@ -81,6 +82,10 @@ func (h *BaseJSHandle) AsElement() *ElementHandle {
8182
func (h *BaseJSHandle) Dispose() {
8283
fmt.Println(">>>>>>: BaseJSHandler Dispose")
8384
if err := h.dispose(); err != nil {
85+
if errors.Is(err, context.Canceled) {
86+
fmt.Println(">>>>>>: Skipping context canceled error on Dispose", err)
87+
return
88+
}
8489
fmt.Println(">>>>>>: BaseJSHandler Dispose error", err)
8590
k6ext.Panic(h.ctx, "dispose: %w", err)
8691
}

0 commit comments

Comments
 (0)