Skip to content

Fix data race#64

Merged
patrickmn merged 1 commit into
patrickmn:masterfrom
inf-rno:master
Jul 22, 2017
Merged

Fix data race#64
patrickmn merged 1 commit into
patrickmn:masterfrom
inf-rno:master

Conversation

@inf-rno

@inf-rno inf-rno commented Jul 21, 2017

Copy link
Copy Markdown
Contributor
  • the gc finalize for an object races with the janitor.Run goroutine
  • because the janitor.stop channel is created in the Run() goroutine this leads
    to a data race.
  • fix by creating the channel when the janitor is created

cc @Shopify/analytics-stack

- the gc finalize for an object races with the janitor.Run goroutine
- because the janitor.stop channel is created in the Run() goroutine this leads
  to a data race.
- fix by creating the channel when the janitor is created
@inf-rno inf-rno changed the title Fix race condition Jul 21, 2017
@inf-rno

inf-rno commented Jul 21, 2017

Copy link
Copy Markdown
Contributor Author

Looks something like this with the race detector

WARNING: DATA RACE
Write at 0x00c42029b208 by goroutine 97:
 /github.com/pmylund/go-cache.(*janitor).Run()
      /github.com/pmylund/go-cache/cache.go:1077 +0x7f

Previous read at 0x00c42029b208 by goroutine 5:
  /github.com/pmylund/go-cache.stopJanitor()
      /github.com/pmylund/go-cache/cache.go:1091 +0x72

Goroutine 97 (running) created at:
  /github.com/pmylund/go-cache.runJanitor()
      /github.com/pmylund/go-cache/cache.go:1099 +0xe0
 /github.com/pmylund/go-cache.newCacheWithJanitor()     
      /github.com/pmylund/go-cache/cache.go:1122 +0x159
 /github.com/pmylund/go-cache.New()
      /github.com/pmylund/go-cache/cache.go:1135 +0x7b

Goroutine 5 (running) created at:
  runtime.createfing()
      /usr/local/go/src/runtime/mfinal.go:142 +0x61
  os.init()
      /usr/local/go/src/os/file.go:54 +0x3d5
  main.init()
     /_test/_testmain.go:78 +0x9f
@patrickmn patrickmn merged commit a3647f8 into patrickmn:master Jul 22, 2017
@patrickmn

Copy link
Copy Markdown
Owner

/embarrassed

thanks

@patrickmn patrickmn mentioned this pull request Sep 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants