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

encoding/gob: data race on nameToConcreteType/concreteTypeToName #4214

Closed
dvyukov opened this issue Oct 8, 2012 · 3 comments
Closed

encoding/gob: data race on nameToConcreteType/concreteTypeToName #4214

dvyukov opened this issue Oct 8, 2012 · 3 comments
Milestone

Comments

@dvyukov
Copy link
Member

dvyukov commented Oct 8, 2012

14564:3350c94fe6b7 tip
Add the following test to encoding/gob package:

func TestStressParallel(t *testing.T) {
    type T2 struct{ A int }
    c := make(chan bool)
    const N = 10
    for i := 0; i < N; i++ {
        go func() {
            p := new(T2)
            Register(p)
            b := new(bytes.Buffer)
            enc := NewEncoder(b)
            err := enc.Encode(p)
            if err != nil {
                t.Error("encoder fail:", err)
            }
            dec := NewDecoder(b)
            err = dec.Decode(p)
            if err != nil {
                t.Error("decoder fail:", err)
            }
            c <- true
        }()
    }
    for i := 0; i < N; i++ {
        <-c
    }
}

go test -race says:

WARNING: DATA RACE
Read by goroutine 69:
  encoding/gob.RegisterName()
      /usr/local/google/home/dvyukov/go_prefetch/src/pkg/encoding/gob/type.go:729 +0xde
  encoding/gob.Register()
      /usr/local/google/home/dvyukov/go_prefetch/src/pkg/encoding/gob/type.go:785 +0x202
  encoding/gob.func·023()
      /usr/local/google/home/dvyukov/go_prefetch/src/pkg/encoding/gob/type_test.go:201 +0x4d

Previous write by goroutine 68:
  encoding/gob.RegisterName()
      /usr/local/google/home/dvyukov/go_prefetch/src/pkg/encoding/gob/type.go:738 +0x26d
  encoding/gob.Register()
      /usr/local/google/home/dvyukov/go_prefetch/src/pkg/encoding/gob/type.go:785 +0x202
  encoding/gob.func·023()
      /usr/local/google/home/dvyukov/go_prefetch/src/pkg/encoding/gob/type_test.go:201 +0x4d

Goroutine 69 (running) created at:
  encoding/gob.TestParallel()
      /usr/local/google/home/dvyukov/go_prefetch/src/pkg/encoding/gob/type_test.go:214 +0xac
  testing.tRunner()
      /usr/local/google/home/dvyukov/go_prefetch/src/pkg/testing/testing.go:301 +0x86

Goroutine 68 (running) created at:
  encoding/gob.TestParallel()
      /usr/local/google/home/dvyukov/go_prefetch/src/pkg/encoding/gob/type_test.go:214 +0xac
  testing.tRunner()
      /usr/local/google/home/dvyukov/go_prefetch/src/pkg/testing/testing.go:301 +0x86
@dvyukov
Copy link
Member Author

dvyukov commented Oct 8, 2012

Comment 1:

Race on global hashmap, can lead to arbitrary memory corruptions.
p.s. this is already reproducible on tip.

@dvyukov
Copy link
Member Author

dvyukov commented Oct 8, 2012

Comment 2:

Test case is in https://golang.org/cl/6619068/

@robpike
Copy link
Contributor

robpike commented Oct 9, 2012

Comment 3:

This issue was closed by revision e855fcc.

Status changed to Fixed.

@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
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