Skip to content

Commit

Permalink
Add fix to prevent panic when ctx closed
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ankur22 committed Apr 8, 2024
1 parent 019ac1c commit e8440a0
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions common/js_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package common

import (
"context"
"errors"
"fmt"

"github.com/grafana/xk6-browser/k6ext"
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit e8440a0

Please sign in to comment.