-
Notifications
You must be signed in to change notification settings - Fork 41
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
Data race due to concurrent map access #1066
Comments
Found another one: 2167394 |
And another: 2272052 |
We've seen a few occurrences of this now, and the thing that they have in common are: At the moment I suspect it's either us not working with logrus and hooks in a concurrent safe way, or it's logrus. |
When running the test script in this issue with
It would result in the following error: Stack trace and error==================
WARNING: DATA RACE 2/5 VUs, 0 complete and 0 interrupted iterations
Read at 0x00c00229bb30 by goroutine 17:-------] 2/5 VUs 04.6s/40.0s
go.k6.io/k6/log.(*lokiHook).Listen()
go.k6.io/[email protected]/log/loki.go:234 +0x730
go.k6.io/k6/cmd.(*rootCommand).setLoggerHook.func1()
go.k6.io/[email protected]/cmd/root.go:287 +0x60
Previous write at 0x00c00229bb30 by goroutine 109:
runtime.mapassign_faststr()
runtime/map_faststr.go:203 +0x40c
github.com/grafana/xk6-browser/log.(*consoleLogFormatter).Format()
github.com/grafana/[email protected]/log/logger.go:188 +0x130
github.com/sirupsen/logrus.(*Entry).write()
github.com/sirupsen/[email protected]/entry.go:289 +0xe0
github.com/sirupsen/logrus.(*Entry).log()
github.com/sirupsen/[email protected]/entry.go:252 +0x730
github.com/sirupsen/logrus.(*Entry).Log()
github.com/sirupsen/[email protected]/entry.go:304 +0x80
github.com/sirupsen/logrus.(*Entry).Info()
github.com/sirupsen/[email protected]/entry.go:321 +0x44
github.com/grafana/xk6-browser/common.(*FrameSession).onConsoleAPICalled()
github.com/grafana/[email protected]/common/frame_session.go:639 +0x3bc
github.com/grafana/xk6-browser/common.(*FrameSession).initEvents.func1()
github.com/grafana/[email protected]/common/frame_session.go:272 +0x598
Goroutine 17 (running) created at:
go.k6.io/k6/cmd.(*rootCommand).setLoggerHook()
go.k6.io/[email protected]/cmd/root.go:286 +0x130
go.k6.io/k6/cmd.(*rootCommand).setupLoggers()
go.k6.io/[email protected]/cmd/root.go:265 +0x920
go.k6.io/k6/cmd.(*rootCommand).persistentPreRunE()
go.k6.io/[email protected]/cmd/root.go:78 +0x40
go.k6.io/k6/cmd.(*rootCommand).persistentPreRunE-fm()
<autogenerated>:1 +0x54
github.com/spf13/cobra.(*Command).execute()
github.com/spf13/[email protected]/command.go:835 +0x6b4
github.com/spf13/cobra.(*Command).ExecuteC()
github.com/spf13/[email protected]/command.go:974 +0x45c
github.com/spf13/cobra.(*Command).Execute()
github.com/spf13/[email protected]/command.go:902 +0x158
go.k6.io/k6/cmd.(*rootCommand).execute()
go.k6.io/[email protected]/cmd/root.go:108 +0x144
go.k6.io/k6/cmd.Execute()
go.k6.io/[email protected]/cmd/root.go:130 +0x38
main.main()
k6/main.go:12 +0x20
Goroutine 109 (running) created at:
github.com/grafana/xk6-browser/common.(*FrameSession).initEvents()
github.com/grafana/[email protected]/common/frame_session.go:223 +0x280
github.com/grafana/xk6-browser/common.NewFrameSession()
github.com/grafana/[email protected]/common/frame_session.go:132 +0x994
github.com/grafana/xk6-browser/common.NewPage()
github.com/grafana/[email protected]/common/page.go:299 +0x8b0
github.com/grafana/xk6-browser/common.(*Browser).onAttachedToTarget()
github.com/grafana/[email protected]/common/browser.go:253 +0x3d0
github.com/grafana/xk6-browser/common.(*Browser).initEvents.func1()
github.com/grafana/[email protected]/common/browser.go:192 +0x2f4
==================
==================
WARNING: DATA RACE
Read at 0x00c001fd6038 by goroutine 17:
go.k6.io/k6/log.(*lokiHook).Listen()
go.k6.io/[email protected]/log/loki.go:242 +0x86c
go.k6.io/k6/cmd.(*rootCommand).setLoggerHook.func1()
go.k6.io/[email protected]/cmd/root.go:287 +0x60
Previous write at 0x00c001fd6038 by goroutine 109:
github.com/grafana/xk6-browser/log.(*consoleLogFormatter).Format()
github.com/grafana/[email protected]/log/logger.go:187 +0xcc
github.com/sirupsen/logrus.(*Entry).write()
github.com/sirupsen/[email protected]/entry.go:289 +0xe0
github.com/sirupsen/logrus.(*Entry).log()
github.com/sirupsen/[email protected]/entry.go:252 +0x730
github.com/sirupsen/logrus.(*Entry).Log()
github.com/sirupsen/[email protected]/entry.go:304 +0x80
github.com/sirupsen/logrus.(*Entry).Info()
github.com/sirupsen/[email protected]/entry.go:321 +0x44
github.com/grafana/xk6-browser/common.(*FrameSession).onConsoleAPICalled()
github.com/grafana/[email protected]/common/frame_session.go:639 +0x3bc
github.com/grafana/xk6-browser/common.(*FrameSession).initEvents.func1()
github.com/grafana/[email protected]/common/frame_session.go:272 +0x598
Goroutine 17 (running) created at:
go.k6.io/k6/cmd.(*rootCommand).setLoggerHook()
go.k6.io/[email protected]/cmd/root.go:286 +0x130
go.k6.io/k6/cmd.(*rootCommand).setupLoggers()
go.k6.io/[email protected]/cmd/root.go:265 +0x920
go.k6.io/k6/cmd.(*rootCommand).persistentPreRunE()
go.k6.io/[email protected]/cmd/root.go:78 +0x40
go.k6.io/k6/cmd.(*rootCommand).persistentPreRunE-fm()
<autogenerated>:1 +0x54
github.com/spf13/cobra.(*Command).execute()
github.com/spf13/[email protected]/command.go:835 +0x6b4
github.com/spf13/cobra.(*Command).ExecuteC()
github.com/spf13/[email protected]/command.go:974 +0x45c
github.com/spf13/cobra.(*Command).Execute()
github.com/spf13/[email protected]/command.go:902 +0x158
go.k6.io/k6/cmd.(*rootCommand).execute()
go.k6.io/[email protected]/cmd/root.go:108 +0x144
go.k6.io/k6/cmd.Execute()
go.k6.io/[email protected]/cmd/root.go:130 +0x38
main.main()
k6/main.go:12 +0x20
Goroutine 109 (running) created at:
github.com/grafana/xk6-browser/common.(*FrameSession).initEvents()
github.com/grafana/[email protected]/common/frame_session.go:223 +0x280
github.com/grafana/xk6-browser/common.NewFrameSession()
github.com/grafana/[email protected]/common/frame_session.go:132 +0x994
github.com/grafana/xk6-browser/common.NewPage()
github.com/grafana/[email protected]/common/page.go:299 +0x8b0
github.com/grafana/xk6-browser/common.(*Browser).onAttachedToTarget()
github.com/grafana/[email protected]/common/browser.go:253 +0x3d0
github.com/grafana/xk6-browser/common.(*Browser).initEvents.func1()
github.com/grafana/[email protected]/common/browser.go:192 +0x2f4
================== Although it might not seem the same as the original issue (it does show some similarities: The stack trace in this comment shows that this issue is within the logger.formatter which is deleting the The loki hook works asynchronously, and the entry (the log message and the metadata) is sent to the hook first and then it is formatted and written to The two possible fixes are:
Having explored the codebase, I feel that now there isn't as much value in keeping the formatter, which is only used in one part of our codebase when logging the Thanks to @mstoykov for pointing this out. |
Brief summary
The following test script reproduces a data race for concurrent access on a map:
Which produces the following [truncated] output:
output
LoadTestRun: 2001281
This happened in another test run. ID: 2037840
output
xk6-browser version
v0.46.0
OS
Linux
Chrome version
119.0.6035.3
Docker version and image (if applicable)
No response
Steps to reproduce the problem
Run the test script (might require multiple executions to reproduce the data race).
Expected behaviour
The test finishes correctly.
Actual behaviour
Test panics due to a data race.
Tasks
The text was updated successfully, but these errors were encountered: