grafana / xk6-browser

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

Concurrent write error with waitForEvent.js example script #1048

Closed ankur22 closed 6 months ago

ankur22 commented 11 months ago

Brief summary

When running the waitForEvent.js example script in the CI it is failing (not on all runs though) on fatal error: concurrent map writes. I'm unable to reproduce this locally though. My initial guess is that the predicateFn call needs to be made on the taskqueue like we do for page.on('console').

xk6-browser version

a7598e135deecb7ac1f64bea605feb547fda345d

OS

NA

Chrome version

NA

Docker version and image (if applicable)

NA

Steps to reproduce the problem

Run the examples/waitForEvent.js test script in the CI and it might result in an error. It doesn't seem to occur on all runs. I've failed to reproduce it locally.

Expected behaviour

The test to run without any issues.

Actual behaviour

The test fails with the following output:

fatal error: concurrent map writes

goroutine 58 [running]:
github.com/dop251/goja.(*Runtime).fieldsInfo(0xc002428800, {0x19eef48, 0x168f480})
    github.com/dop251/goja@v0.0.0-20230919151941-fc55792775de/object_goreflect.go:627 +0xbc
github.com/dop251/goja.(*objectGoReflect).init(0xc002a702a0)
    github.com/dop251/goja@v0.0.0-20230919151941-fc55792775de/object_goreflect.go:150 +0x50b
github.com/dop251/goja.(*Runtime).toValue(0xc002428800, {0x16cb400?, 0xc001bca340?}, {0x0?, 0x0?, 0x1?})
    github.com/dop251/goja@v0.0.0-20230919151941-fc55792775de/runtime.go:1919 +0x1885
github.com/dop251/goja.(*Runtime).ToValue(...)
    github.com/dop251/goja@v0.0.0-20230919151941-fc55792775de/runtime.go:1735
github.com/grafana/xk6-browser/common.(*BrowserContext).runWaitForEventHandler(0xc0023822c0, {0x19da488, 0xc000faa910}, 0xc0023cbf20, 0xc0023cbf80, 0xc00004e420, 0xc001ceb260)
    github.com/grafana/xk6-browser@v1.0.2/common/browser_context.go:442 +0x39d
created by github.com/grafana/xk6-browser/common.(*BrowserContext).waitForEvent in goroutine 55
    github.com/grafana/xk6-browser@v1.0.2/common/browser_context.go:382 +0x286

goroutine 1 [chan receive]:
go.k6.io/k6/execution.(*Scheduler).Run(0xc000ee08c0, {0x19da488, 0xc0000945f0}, {0x19da450, 0xc00070f560}, 0xc002320c00)
    go.k6.io/k6@v0.46.1-0.20230926095547-6fa8abddf10c/execution/scheduler.go:[472](https://github.com/grafana/xk6-browser/actions/runs/6311217342/job/17134781659?pr=1047#step:7:473) +0xc6e
go.k6.io/k6/cmd.(*cmdRun).run(0xc00006c340, 0xc0001c1680, {0xc000088960?, 0x1, 0x2})
    go.k6.io/k6@v0.46.1-0.20230926095547-6fa8abddf10c/cmd/run.go:352 +0x1531
github.com/spf13/cobra.(*Command).execute(0xc0001c1680, {0xc000088940, 0x2, 0x2})
    github.com/spf13/cobra@v1.4.0/command.go:856 +0x694
github.com/spf13/cobra.(*Command).ExecuteC(0xc0002c8c80)
    github.com/spf13/cobra@v1.4.0/command.go:974 +0x38d
github.com/spf13/cobra.(*Command).Execute(...)
    github.com/spf13/cobra@v1.4.0/command.go:902
go.k6.io/k6/cmd.(*rootCommand).execute(0xc0002b51d0)
    go.k6.io/k6@v0.46.1-0.20230926095547-6fa8abddf10c/cmd/root.go:104 +0x125
go.k6.io/k6/cmd.Execute()
    go.k6.io/k6@v0.46.1-0.20230926095547-6fa8abddf10c/cmd/root.go:137 +0x2f
main.main()
goroutine 96 [select]:
github.com/grafana/xk6-browser/common.contextWithDoneChan.func1()
    github.com/grafana/xk6-browser@v1.0.2/common/context.go:61 +0x7c
created by github.com/grafana/xk6-browser/common.contextWithDoneChan in goroutine 27
    github.com/grafana/xk6-browser@v1.0.2/common/context.go:59 +0xb6

goroutine 126 [select]:
github.com/grafana/xk6-browser/common.contextWithDoneChan.func1()
    github.com/grafana/xk6-browser@v1.0.2/common/context.go:61 +0x7c
created by github.com/grafana/xk6-browser/common.contextWithDoneChan in goroutine 27
    github.com/grafana/xk6-browser@v1.0.2/common/context.go:59 +0xb6

goroutine 138 [select]:
github.com/grafana/xk6-browser/common.contextWithDoneChan.func1()
    github.com/grafana/xk6-browser@v1.0.2/common/context.go:61 +0x7c
created by github.com/grafana/xk6-browser/common.contextWithDoneChan in goroutine 27
    github.com/grafana/xk6-browser@v1.0.2/common/context.go:59 +0xb6

goroutine 149 [select]:
github.com/grafana/xk6-browser/common.contextWithDoneChan.func1()
    github.com/grafana/xk6-browser@v1.0.2/common/context.go:61 +0x7c
created by github.com/grafana/xk6-browser/common.contextWithDoneChan in goroutine 27
    github.com/grafana/xk6-browser@v1.0.2/common/context.go:59 +0xb6

goroutine 135 [select]:
github.com/grafana/xk6-browser/common.contextWithDoneChan.func1()
    github.com/grafana/xk6-browser@v1.0.2/common/context.go:61 +0x7c
created by github.com/grafana/xk6-browser/common.contextWithDoneChan in goroutine 27
    github.com/grafana/xk6-browser@v1.0.2/common/context.go:59 +0xb6

goroutine 145 [select]:
github.com/grafana/xk6-browser/common.contextWithDoneChan.func1()
    github.com/grafana/xk6-browser@v1.0.2/common/context.go:61 +0x7c
created by github.com/grafana/xk6-browser/common.contextWithDoneChan in goroutine 27
    github.com/grafana/xk6-browser@v1.0.2/common/context.go:59 +0xb6

goroutine 140 [select]:
github.com/grafana/xk6-browser/common.contextWithDoneChan.func1()
    github.com/grafana/xk6-browser@v1.0.2/common/context.go:61 +0x7c
created by github.com/grafana/xk6-browser/common.contextWithDoneChan in goroutine 27
    github.com/grafana/xk6-browser@v1.0.2/common/context.go:59 +0xb6

goroutine 152 [select]:
github.com/grafana/xk6-browser/common.contextWithDoneChan.func1()
    github.com/grafana/xk6-browser@v1.0.2/common/context.go:61 +0x7c
created by github.com/grafana/xk6-browser/common.contextWithDoneChan in goroutine 27
    github.com/grafana/xk6-browser@v1.0.2/common/context.go:59 +0xb6
Error: Process completed with exit code 2.
inancgumus commented 11 months ago

Thanks! It might be because of the concurrency issue as in page.On as you said 👍 Before the task queue starts infiltrating much into the business logic; my humble suggestion is to abstract it in the mapping layer while solving this problem :)

inancgumus commented 11 months ago

Happened again: https://github.com/grafana/xk6-browser/actions/runs/6326006299/job/17178693049.

ankur22 commented 6 months ago

I believe this issue has been resolved by https://github.com/grafana/xk6-browser/issues/447, and some refactoring in https://github.com/grafana/xk6-browser/issues/1187.