grafana / xk6-browser

The browser module adds support for browser automation and end-to-end web testing via the Chrome Devtools Protocol to k6.
https://grafana.com/docs/k6/latest/javascript-api/k6-browser/
GNU Affero General Public License v3.0
344 stars 41 forks source link

`getOwnerFrame` `nil` pointer #1416

Closed inancgumus closed 1 month ago

inancgumus commented 2 months ago

What?

Panic occurs while running page.getOwnerFrame, here:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x138 pc=0x154713f]

goroutine 3623769 [running]:
github.com/grafana/xk6-browser/common.(*Page).getOwnerFrame(0xc04ef1fba0, {0x1eee958, 0xc133120cb0}, 0xc015ca2370)
github.com/grafana/xk6-browser@v1.7.1/common/page.go:489 +0x6bf
github.com/grafana/xk6-browser/common.(*ElementHandle).ownerFrame(0xc015ca2370, {0x1eee958?, 0xc133120cb0?})
github.com/grafana/xk6-browser@v1.7.1/common/element_handle.go:431 +0x45
github.com/grafana/xk6-browser/common.(*ElementHandle).checkHitTargetAt(0xc015ca2370, {0x1eee958?, 0xc133120cb0?}, {0x4084000000000000, 0x407cdf8000000000})
github.com/grafana/xk6-browser@v1.7.1/common/element_handle.go:67 +0x49
github.com/grafana/xk6-browser/common.(*ElementHandle).newPointerAction.func1({0x1eee958, 0xc133120cb0}, 0x0?)
github.com/grafana/xk6-browser@v1.7.1/common/element_handle.go:1621 +0x532
github.com/grafana/xk6-browser/common.retryPointerAction({0x1eee958, 0xc133120cb0}, 0xc1854851a0, 0xc06e7e01e0)
github.com/grafana/xk6-browser@v1.7.1/common/element_handle.go:1660 +0x3c
github.com/grafana/xk6-browser/common.(*ElementHandle).newPointerAction.func2({0x1eee958?, 0xc133120cb0?}, 0xc01f554ba0, 0xc01f554c60)
github.com/grafana/xk6-browser@v1.7.1/common/element_handle.go:1648 +0x45
github.com/grafana/xk6-browser/common.(*Frame).click.(*Frame).newPointerAction.func2({0x1eee958, 0xc133120cb0}, 0xc01f554ba0, 0xc01f554c60)
github.com/grafana/xk6-browser@v1.7.1/common/frame.go:2181 +0x116
created by github.com/grafana/xk6-browser/common.call in goroutine 3623768
github.com/grafana/xk6-browser@v1.7.1/common/helpers.go:103 +0x14c

Why?

Needs to be investigated.

How?

No response

Tasks

### Tasks
- [ ] https://github.com/grafana/xk6-browser/pull/1435
- [ ] Update the k6 release notes

Related PR(s)/Issue(s)

No response

ankur22 commented 2 months ago

I've investigated this issue and compared it with Playwright. Here are my findings:

The NPD currently can occur in getOwnerFrame. In Playwright, fortunately, they have an equivalent method and they actually check for null.

I think the safest option is to protect against a NPD here by also checking for null. Unfortunately, i've not been able to replicate the issue in the first place.

WDYT @inancgumus?

inancgumus commented 2 months ago

@ankur22 Sounds good to me 👍

joanlopez commented 1 month ago

Found another NPD that @ankur22 suggests it's similar to this one. Here are the details:

panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x15924a8]

goroutine 368053 [running]:
go.opentelemetry.io/otel/sdk/trace.(*recordingSpan).End.deferwrap1()
go.opentelemetry.io/otel/sdk@v1.29.0/trace/span.go:398 +0x25
go.opentelemetry.io/otel/sdk/trace.(*recordingSpan).End(0xc043cfcb60, {0x0, 0x0, 0xc01a2ae8c0?})
go.opentelemetry.io/otel/sdk@v1.29.0/trace/span.go:436 +0xa62
panic({0x1922540?, 0x2eb2e90?})
runtime/panic.go:785 +0x132
github.com/grafana/xk6-browser/common.(*screenshotter).screenshot(0xc049415eb0, {0x1f2ac00, 0xc014e5a0a0}, 0x0, 0xc049415ca8, {0x1bae2fb, 0x3}, 0x0, 0xc010762600?, {0xc013f74840, ...})
github.com/grafana/xk6-browser@v1.8.5/common/screenshotter.go:185 +0x328
github.com/grafana/xk6-browser/common.(*screenshotter).screenshotPage(0xc049415eb0, 0xc01ce864e0, 0xc010762580)
github.com/grafana/xk6-browser@v1.8.5/common/screenshotter.go:398 +0x334
github.com/grafana/xk6-browser/common.(*Page).Screenshot(0xc01ce864e0, 0xc010762580, {0x7f7cc4265108, 0xc001078540})
github.com/grafana/xk6-browser@v1.8.5/common/page.go:1146 +0x2c6
github.com/grafana/xk6-browser/browser.mapPage.func34.1()
github.com/grafana/xk6-browser@v1.8.5/browser/page_mapping.go:255 +0x4e
github.com/grafana/xk6-browser/k6ext.promise.func1()
github.com/grafana/xk6-browser@v1.8.5/k6ext/promise.go:41 +0x5a
created by github.com/grafana/xk6-browser/k6ext.promise in goroutine 108
github.com/grafana/xk6-browser@v1.8.5/k6ext/promise.go:40 +0xe6

Thanks! 🙇🏻

ankur22 commented 1 month ago

@joanlopez, sorry, at the time I gave you the wrong issue, i meant https://github.com/grafana/xk6-browser/issues/1056 🤦 Now we have a dedicated issue https://github.com/grafana/xk6-browser/issues/1502.

ankur22 commented 1 month ago

@inancgumus I believe we can close this. I've not seen this issue since the fix. WDYT?

inancgumus commented 1 month ago

Sure, we can resurrect it if it happens again.