Skip to content

runtime: missed write barrier with race detector #12068

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

Closed
rsc opened this issue Aug 7, 2015 · 5 comments
Closed

runtime: missed write barrier with race detector #12068

rsc opened this issue Aug 7, 2015 · 5 comments
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Aug 7, 2015

Reported on golang-dev by carl@stripe.com. This program, reduced from a much larger one, crashes due to GC missing objects when run under the race detector. Best suspect is missed write barrier in that mode.

GODEBUG=gccheckmark=1 go run -race heavy.go 

package main

type Interface interface {
    Dummy()
}

type Thing1 struct {
    a, b *int
}

type Thing2 struct {
    Thing1
}

func (_ Thing2) Dummy() {}

func NewThing1() Thing1 {
    return Thing1{new(int), new(int)}
}

func NewThing2() Interface {
    return &Thing2{NewThing1()}
}

func main() {
    for i := 0; i < 20; i++ {
        go func() {
            for {
                t := NewThing2()
                t.Dummy()
            }
        }()
    }
    <-make(chan struct{})
}

Damian Gryski suggests perhaps the bug was introduced on github.com/golang/go/commit/8f34b25318e712a18c3847bb1cc3e8d87076c211.

@rsc rsc self-assigned this Aug 7, 2015
@rsc rsc added this to the Go1.5 milestone Aug 7, 2015
@rsc
Copy link
Contributor Author

rsc commented Aug 7, 2015

@aclements @RLH FYI, but I don't think this is the GC's fault.

@dgryski
Copy link
Contributor

dgryski commented Aug 7, 2015

A more accurate description of my git-bisect attempts is that there have been a number of commits that made this occur with increasing frequency. Ranging from once every 20min of testing at the above commit to every 3-4 seconds with tip. These changes tend to be at a point where the gc has been tweaked.

@rsc rsc changed the title cmd/compile: missed write barrier with race detector runtime: missed write barrier with race detector Aug 7, 2015
@rsc
Copy link
Contributor Author

rsc commented Aug 7, 2015

Variant that exits, for testing:

package main

type Interface interface {
    Dummy()
}

type Thing1 struct {
    a, b *int
}

type Thing2 struct {
    Thing1
}

func (_ Thing2) Dummy() {}

func NewThing1() Thing1 {
    return Thing1{new(int), new(int)}
}

func NewThing2() Interface {
    return &Thing2{NewThing1()}
}

func hammer(n int, c chan int) {
    for i := 0; i < n; i++ {
        t := NewThing2()
        t.Dummy()
    }
    c <- 1
}

func main() {
    c := make(chan int)
    for i := 0; i < 20; i++ {
        go hammer(2000000, c)
    }
    for i := 0; i < 20; i++ {
        <-c
    }
}

@rsc
Copy link
Contributor Author

rsc commented Aug 7, 2015

Fix in CL 13364.

@rsc rsc closed this as completed in 3ae1704 Aug 7, 2015
@zenazn
Copy link
Contributor

zenazn commented Aug 7, 2015

Thanks, @rsc!

@golang golang locked and limited conversation to collaborators Aug 8, 2016
@rsc rsc removed their assignment Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants