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

[BUG] - Race condition #43

Open
ALX99 opened this issue Dec 28, 2024 · 0 comments
Open

[BUG] - Race condition #43

ALX99 opened this issue Dec 28, 2024 · 0 comments

Comments

@ALX99
Copy link

ALX99 commented Dec 28, 2024

Describe the bug
Race condition

To Reproduce
Steps to reproduce the behavior:

  1. Enable race detector
  2. Try to log something that calls WithAttrs() and Handle() at the same time
  3. Should panic

Expected behavior
No panic

Screenshots

WARNING: DATA RACE
Write at 0x00c000134a98 by goroutine 24:
  sync/atomic.CompareAndSwapInt32()
      /usr/lib/go/src/runtime/race_amd64.s:361 +0xb
  sync/atomic.CompareAndSwapInt32()
      <autogenerated>:1 +0x18
  github.com/golang-cz/devslog.(*developHandler).Handle()
      /go/pkg/mod/github.com/golang-cz/[email protected]/devslog.go:165 +0x552
  log/slog.(*Logger).logAttrs()
      /usr/lib/go/src/log/slog/logger.go:277 +0x228
  log/slog.(*Logger).LogAttrs()
      /usr/lib/go/src/log/slog/logger.go:195 +0x1a9
  github.com/alx99/ika/internal/logger.Initialize.func2()
      /projects/ika/internal/logger/logger.go:72 +0x175

Previous read at 0x00c000134a98 by main goroutine:
  github.com/golang-cz/devslog.(*developHandler).withGroupOrAttrs()
      /go/pkg/mod/github.com/golang-cz/[email protected]/devslog.go:150 +0xb0
  github.com/golang-cz/devslog.(*developHandler).WithAttrs()
      /go/pkg/mod/github.com/golang-cz/[email protected]/devslog.go:146 +0x58
  log/slog.(*Logger).With()
      /usr/lib/go/src/log/slog/logger.go:132 +0x106
  github.com/alx99/ika/internal/plugins.(*Dumper).Handler()
      /projects/ika/internal/plugins/dumper.go:32 +0xe4
  github.com/alx99/ika/plugin.Middleware.Handler-fm()
      <autogenerated>:1 +0x61
  github.com/alx99/ika/internal/http/router/chain.Chain.Then()
      /projects/ika/internal/http/router/chain/chain.go:62 +0x8b
  github.com/alx99/ika/internal/http/router.MakeRouter()
      /projects/ika/internal/http/router/router.go:125 +0x2fbb
  github.com/alx99/ika/internal/ika.run()
      /projects/ika/internal/ika/ika.go:62 +0x30f
  github.com/alx99/ika/internal/ika.Run()
      /projects/ika/internal/ika/ika.go:28 +0x176
  github.com/alx99/ika.Run()
      /projects/ika/ika.go:32 +0x2e7
  main.main()
      /projects/ika/cmd/ika/main.go:10 +0x3e

Goroutine 24 (running) created at:
  github.com/alx99/ika/internal/logger.Initialize()
      /projects/ika/internal/logger/logger.go:66 +0xef5
  github.com/alx99/ika/internal/ika.run()
      /projects/ika/internal/ika/ika.go:60 +0x2bb
  github.com/alx99/ika/internal/ika.Run()
      /projects/ika/internal/ika/ika.go:28 +0x176
  github.com/alx99/ika.Run()
      /projects/ika/ika.go:32 +0x2e7
  main.main()
      /projects/ika/cmd/ika/main.go:10 +0x3e

Desktop (please complete the following information):

  • OS: [e.g. Linux]
  • Version [e.g. 1.21.0]

Additional context

Lock copied by value here:

h2 := *h

Lock used here:

h.mu.Lock()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant