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

x/tools/internal/imports: data-race causes panic due to concurrent map read and write #34895

Closed
a8m opened this issue Oct 14, 2019 · 2 comments
Closed

Comments

@a8m
Copy link
Contributor

@a8m a8m commented Oct 14, 2019

When running imports.Process concurrently, the program panics with a fatal error due to concurrent map iterations and map writes.

I've created a CL that fixes this - https://go-review.googlesource.com/c/tools/+/200865 (so, I'm not sure this Github issue is really needed?)

This can be reproduced as follows:

$ tree
.
├── main.go
└── testdata
    ├── first.go
    └── second.go
main.go

package main

import (
	"log"
	"sync"

	"golang.org/x/tools/imports"
)

func main() {
	var (
		n  = 10
		wg sync.WaitGroup
	)
	wg.Add(n)
	for i := 0; i < n; i++ {
		go func() {
			defer wg.Done()
			_, err := imports.Process("testdata/first.go", nil, nil)
			if err != nil {
				log.Fatal(err)
			}
		}()
	}
	wg.Wait()
}

testdata/first.go

package testdata

func _() {
	fmt.Println()
}

testdata/second.go

package testdata

import "fmt"

func _() {
	fmt.Println()
	imports.Bar() // not imported.
}


Output:

fatal error: concurrent map writes
fatal error: concurrent map writes
fatal error: concurrent map iteration and map write
fatal error: concurrent map writes

goroutine 14 [running]:
runtime.throw(0x1312874, 0x15)
	/usr/local/go/src/runtime/panic.go:774 +0x72 fp=0xc0000dda48 sp=0xc0000dda18 pc=0x102c7f2
runtime.mapassign_faststr(0x12a4840, 0xc000073380, 0x12fafa3, 0x9, 0xc0000e2a8c)
	/usr/local/go/src/runtime/map_faststr.go:211 +0x417 fp=0xc0000ddab0 sp=0xc0000dda48 pc=0x10126c7
....
@gopherbot gopherbot added this to the Unreleased milestone Oct 14, 2019
@gopherbot gopherbot added the Tools label Oct 14, 2019
@julieqiu
Copy link
Contributor

@julieqiu julieqiu commented Oct 15, 2019

@a8m
Copy link
Contributor Author

@a8m a8m commented Oct 18, 2019

Closed with golang/tools@1f7a813

@a8m a8m closed this Oct 18, 2019
@golang golang locked and limited conversation to collaborators Oct 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.