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] - Data Race in RunCount #374

Closed
seunghyupoh3517 opened this issue Aug 15, 2022 · 1 comment
Closed

[BUG] - Data Race in RunCount #374

seunghyupoh3517 opened this issue Aug 15, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@seunghyupoh3517
Copy link

seunghyupoh3517 commented Aug 15, 2022

Describe the bug

=== RUN   TestTimeoutJob
==================
WARNING: DATA RACE
Write at 0x00c000598920 by goroutine 124:
  github.com/go-co-op/gocron.(*Scheduler).run()
      /home/circleci/go/pkg/mod/github.com/go-co-op/gocron@v1.16.1/scheduler.go:554 +0x106a
  github.com/go-co-op/gocron.(*Scheduler).runContinuous()
      /home/circleci/go/pkg/mod/github.com/go-co-op/gocron@v1.16.1/scheduler.go:566 +0x8e
  github.com/go-co-op/gocron.(*Scheduler).runContinuous.func1()
      /home/circleci/go/pkg/mod/github.com/go-co-op/gocron@v1.16.1/scheduler.go:579 +0x237

Previous read at 0x00c000598920 by goroutine 98:
  github.com/go-co-op/gocron.(*Job).RunCount()
      /home/circleci/go/pkg/mod/github.com/go-co-op/gocron@v1.16.1/job.go:437 +0xbc
  github.com/fluxninja/aperture/pkg/jobs.(*jobExecutor).jobInfo()
      /root/project/pkg/jobs/job.go:235 +0x94
  github.com/fluxninja/aperture/pkg/jobs.(*JobGroup).JobInfo()
      /root/project/pkg/jobs/job-group.go:277 +0x1d2
  github.com/fluxninja/aperture/pkg/jobs.(*groupConfig).OnJobCompleted()
      /root/project/pkg/jobs/jobs_test.go:69 +0xda
  github.com/fluxninja/aperture/pkg/jobs.runTest()
      /root/project/pkg/jobs/jobs_test.go:105 +0x925
  github.com/fluxninja/aperture/pkg/jobs.TestTimeoutJob()
      /root/project/pkg/jobs/jobs_test.go:189 +0x32d
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1446 +0x216
  testing.(*T).Run.func1()
      /usr/local/go/src/testing/testing.go:1493 +0x47

Goroutine 124 (running) created at:
  time.goFunc()
      /usr/local/go/src/time/sleep.go:176 +0x47

Goroutine 98 (running) created at:
  testing.(*T).Run()
      /usr/local/go/src/testing/testing.go:1493 +0x75d
  testing.runTests.func1()
      /usr/local/go/src/testing/testing.go:1846 +0x99
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1446 +0x216
  testing.runTests()
      /usr/local/go/src/testing/testing.go:1844 +0x7ec
  testing.(*M).Run()
      /usr/local/go/src/testing/testing.go:1726 +0xa84
  main.main()
      _testmain.go:1043 +0x3da
==================

To Reproduce

Steps to reproduce the behavior:
When *Scheduler.run(), scheduler is executing the job and in another go routine, tries to access the JobInfo using Job.RunCount(), Job.NextRun(), Job.LastRun(), Job.RunCount() is not being protected by mutex and leads to data race.

Version

github.com/go-co-op/gocron@v1.16.1

Expected behavior

There shouldn't be data race when *Scheduler.run()

Additional context

@seunghyupoh3517
Copy link
Author

@JohnRoesler I have added quick fix for this data race, please take a look!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants