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

Data race #17

Closed
ericlagergren opened this issue Mar 14, 2016 · 3 comments
Closed

Data race #17

ericlagergren opened this issue Mar 14, 2016 · 3 comments

Comments

@ericlagergren
Copy link

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
Copy link
Author

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

@davecheney
Copy link
Member

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
#17 (comment).

@ericlagergren
Copy link
Author

No problem!

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

2 participants