project-zot / zot

zot - A scale-out production-ready vendor-neutral OCI-native container image/artifact registry (purely based on OCI Distribution Specification)
https://zotregistry.dev
Apache License 2.0
920 stars 98 forks source link

Fix race conditions in logger #815

Closed andaaron closed 2 years ago

andaaron commented 2 years ago

See https://github.com/project-zot/zot/actions/runs/3121175998/jobs/5062314820

✔✔✔✔==================
WARNING: DATA RACE
Write at 0x0000081b4e40 by goroutine 128:
  zotregistry.io/zot/pkg/log.NewLogger()
      zotregistry.io/zot/pkg/log/log.go:25 +0x91
  zotregistry.io/zot/pkg/api.NewController()
      zotregistry.io/zot/pkg/api/controller.go:52 +0x164
  zotregistry.io/zot/pkg/api_test.TestRoutes.func1()
      zotregistry.io/zot/pkg/api/routes_test.go:36 +0xd6
  github.com/smartystreets/goconvey/convey.parseAction.func1()
      github.com/smartystreets/goconvey@v1.7.2/convey/discovery.go:89 +0x30
  github.com/smartystreets/goconvey/convey.(*context).conveyInner()
      github.com/smartystreets/goconvey@v1.7.2/convey/context.go:279 +0x264
  github.com/smartystreets/goconvey/convey.rootConvey.func1()
      github.com/smartystreets/goconvey@v1.7.2/convey/context.go:112 +0x195
  github.com/jtolds/gls.(*ContextManager).SetValues.func1()
      github.com/jtolds/gls@v4.20.0+incompatible/context.go:97 +0x5c3
  github.com/jtolds/gls.EnsureGoroutineId.func1()
      github.com/jtolds/gls@v4.20.0+incompatible/gid.go:24 +0x3e
  github.com/jtolds/gls._m()
      github.com/jtolds/gls@v4.20.0+incompatible/stack_tags.go:108 +0x41
  github.com/jtolds/gls.github_com_jtolds_gls_markS()
      github.com/jtolds/gls@v4.20.0+incompatible/stack_tags.go:56 +0x36
  github.com/jtolds/gls.addStackTag()
      github.com/jtolds/gls@v4.20.0+incompatible/stack_tags.go:49 +0x15c
  github.com/jtolds/gls.EnsureGoroutineId()
      github.com/jtolds/gls@v4.20.0+incompatible/gid.go:24 +0x26
  github.com/jtolds/gls.(*ContextManager).SetValues()
      github.com/jtolds/gls@v4.20.0+incompatible/context.go:63 +0x29d
  github.com/smartystreets/goconvey/convey.rootConvey()
      github.com/smartystreets/goconvey@v1.7.2/convey/context.go:107 +0x571
  github.com/smartystreets/goconvey/convey.Convey()
      github.com/smartystreets/goconvey@v1.7.2/convey/doc.go:76 +0x9c
  zotregistry.io/zot/pkg/api_test.TestRoutes()
      zotregistry.io/zot/pkg/api/routes_test.go:30 +0xe7
  testing.tRunner()
      testing/testing.go:1439 +0x213
  testing.(*T).Run.func1()
      testing/testing.go:1486 +0x47

Previous read at 0x0000081b4e40 by goroutine 17:
  github.com/rs/zerolog.(*Event).Timestamp()
      github.com/rs/zerolog@v1.28.0/event.go:651 +0x1f5
  github.com/rs/zerolog.timestampHook.Run()
      github.com/rs/zerolog@v1.28.0/context.go:327 +0x44
  github.com/rs/zerolog.(*timestampHook).Run()
      <autogenerated>:1 +0x1d
  github.com/rs/zerolog.(*Event).msg()
      github.com/rs/zerolog@v1.28.0/event.go:141 +0x4f9
  github.com/rs/zerolog.(*Event).Msg()
      github.com/rs/zerolog@v1.28.0/event.go:108 +0x19a
  zotregistry.io/zot/pkg/scheduler.(*generator).generate()
      zotregistry.io/zot/pkg/scheduler/scheduler.go:257 +0x157
  zotregistry.io/zot/pkg/scheduler.(*Scheduler).generateTasks()
      zotregistry.io/zot/pkg/scheduler/scheduler.go:151 +0x210
  zotregistry.io/zot/pkg/scheduler.(*Scheduler).getTask()
      zotregistry.io/zot/pkg/scheduler/scheduler.go:156 +0x44
  zotregistry.io/zot/pkg/scheduler.(*Scheduler).RunScheduler.func1()
      zotregistry.io/zot/pkg/scheduler/scheduler.go:101 +0xc7

Goroutine 128 (running) created at:
  testing.(*T).Run()
      testing/testing.go:1486 +0x724
  testing.runTests.func1()
      testing/testing.go:1839 +0x99
  testing.tRunner()
      testing/testing.go:1439 +0x213
  testing.runTests()
      testing/testing.go:1837 +0x7e4
  testing.(*M).Run()
      testing/testing.go:1719 +0xa71
  main.main()
      _testmain.go:455 +0x3c9

Goroutine 17 (running) created at:
  zotregistry.io/zot/pkg/scheduler.(*Scheduler).RunScheduler()
      zotregistry.io/zot/pkg/scheduler/scheduler.go:93 +0x156
  zotregistry.io/zot/pkg/api.(*Controller).StartBackgroundTasks()
      zotregistry.io/zot/pkg/api/controller.go:448 +0xf4
  zotregistry.io/zot/pkg/api.(*Controller).InitImageStore()
      zotregistry.io/zot/pkg/api/controller.go:322 +0xf4e
  zotregistry.io/zot/pkg/api.(*Controller).Run()
      zotregistry.io/zot/pkg/api/controller.go:157 +0xceb
  zotregistry.io/zot/pkg/api_test.startServer()
      zotregistry.io/zot/pkg/api/controller_test.go:6364 +0x49
  zotregistry.io/zot/pkg/api_test.TestPeriodicGC.func2.2()
      zotregistry.io/zot/pkg/api/controller_test.go:6038 +0x39
==================
andaaron commented 2 years ago

Done in https://github.com/project-zot/zot/pull/817