pkg / profile

Simple profiling for Go
BSD 2-Clause "Simplified" License
2k stars 122 forks source link

Data race #17

Closed ericlagergren closed 8 years ago

ericlagergren commented 8 years ago

Running as shown in the example (i.e., defer profile.Start().Stop()) causes a data race:

eric@archbox /tmp $ cat main.go 
package main

import (
    "time"

    "github.com/pkg/profile"
)

func main() {
    defer profile.Start().Stop()
    time.Sleep(5 * time.Second)
}
eric@archbox /tmp $ go build -race main.go
eric@archbox /tmp $ ./main 
2016/03/14 14:53:07 profile: cpu profiling enabled, /tmp/profile342323605/cpu.pprof
^C2016/03/14 14:53:08 profile: caught interrupt, stopping profiles
==================
WARNING: DATA RACE
Read by goroutine 8:
  github.com/pkg/profile.(*profile).Stop()
      /home/eric/gopath/src/github.com/pkg/profile/profile.go:93 +0x37
  github.com/pkg/profile.Start.func5()
      /home/eric/gopath/src/github.com/pkg/profile/profile.go:181 +0x20c

Previous write by main goroutine:
  github.com/pkg/profile.Start()
      /home/eric/gopath/src/github.com/pkg/profile/profile.go:187 +0xb22
  main.main()
      /tmp/main.go:10 +0x39

Goroutine 8 (running) created at:
  github.com/pkg/profile.Start()
      /home/eric/gopath/src/github.com/pkg/profile/profile.go:184 +0xa14
  main.main()
      /tmp/main.go:10 +0x39
==================
==================
WARNING: DATA RACE
Read by goroutine 8:
  github.com/pkg/profile.(*profile).Stop()
      /home/eric/gopath/src/github.com/pkg/profile/profile.go:93 +0x84
  github.com/pkg/profile.Start.func5()
      /home/eric/gopath/src/github.com/pkg/profile/profile.go:181 +0x20c

Previous write by main goroutine:
  github.com/pkg/profile.Start()
      /home/eric/gopath/src/github.com/pkg/profile/profile.go:189 +0xae3
  main.main()
      /tmp/main.go:10 +0x39

Goroutine 8 (running) created at:
  github.com/pkg/profile.Start()
      /home/eric/gopath/src/github.com/pkg/profile/profile.go:184 +0xa14
  main.main()
      /tmp/main.go:10 +0x39
==================
Found 2 data race(s)
ericlagergren commented 8 years ago

You may need to set export GORACE="history_size=7" to see the writing goroutine.

davecheney commented 8 years ago

Thanks. That looks like an easy fix.

On Tue, Mar 15, 2016 at 8:54 AM, Eric Lagergren notifications@github.com wrote:

You may need to set export GORACE="history_size=7" to see the writing goroutine.

— Reply to this email directly or view it on GitHub https://github.com/pkg/profile/issues/17#issuecomment-196537565.

ericlagergren commented 8 years ago

No problem!