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 23, 2024
1 parent bf721fb commit 483952a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion 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 @@ -79,7 +80,13 @@ func (h *BaseJSHandle) AsElement() *ElementHandle {
// Dispose releases the remote object.
func (h *BaseJSHandle) Dispose() {
if err := h.dispose(); err != nil {
k6ext.Panic(h.ctx, "dispose: %w", err)
// We do not want to panic on an error when the error is a closed
// context. The reason the context would be closed is due to the
// iteration ending and therefore the associated browser and its assets
// will be automatically deleted.
if !errors.Is(err, context.Canceled) {
k6ext.Panic(h.ctx, "dispose: %w", err)
}
}
}

Expand Down

0 comments on commit 483952a

Please sign in to comment.