Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly check if we actually timed out #4132

Merged
merged 2 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion js/modules/k6/browser/common/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,12 +493,22 @@ func (b *Browser) newPageInContext(id cdp.BrowserContextID) (*Page, error) {
page = b.pages[tid]
b.pagesMu.RUnlock()
case <-ctx.Done():
b.logger.Debugf("Browser:newPageInContext:<-ctx.Done", "tid:%v bctxid:%v err:%v", tid, id, ctx.Err())
}

if err = ctx.Err(); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this context be cancelled because any reason other than context.DeadlineExceeded? Perhaps, in a future iteration of this code, we might want to introduce that explicit check or use cause.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding (@ankur22, please correct me if I am wrong) even if that happens it's still an error case

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, any error from context is regarded as an error and we should return an error back to the user to notify them of an issue. If the context is closed at this point, it will mean that the iteration has ended.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right! What I was wondering is whether context.DeadlineExceeded should be considered a timeout error, but context.Canceled shouldn't (but as an unknown). But both errors, yeah.

err = &k6ext.UserFriendlyError{
Err: ctx.Err(),
Timeout: b.browserOpts.Timeout,
}
b.logger.Debugf("Browser:newPageInContext:<-ctx.Done", "tid:%v bctxid:%v err:%v", tid, id, err)
}

if err == nil && page == nil {
err = &k6ext.UserFriendlyError{
Err: errors.New("can't fetch the page for unknown reason"),
}
}

return page, err
}

Expand Down
13 changes: 1 addition & 12 deletions js/modules/k6/browser/common/browser_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,18 +262,7 @@ func (b *BrowserContext) NewPage() (*Page, error) {
return nil, err
}

var (
bctxid cdp.BrowserContextID
ptid target.ID
)
if b != nil {
bctxid = b.id
}
if p != nil {
ptid = p.targetID
}
b.logger.Debugf("BrowserContext:NewPage:return", "bctxid:%v ptid:%s", bctxid, ptid)

b.logger.Debugf("BrowserContext:NewPage:return", "bctxid:%v ptid:%s", b.id, p.targetID)
return p, nil
}

Expand Down
Loading