1
0
mirror of https://github.com/golang/go synced 2024-11-18 16:14:46 -07:00
go/imports
Bryan C. Mills 165bdd618e imports: fix races in findImportGoPath
Before this change, findImportGoPath used a field within the
(otherwise read-only) structs in the dirScan map to cache the distance
from the importing package to the candidate package to be imported. As
a result, the top-level imports.Process function was not safe to call
concurrently: one goroutine could overwrite the distances while
another was attempting to sort by them. Furthermore, there were some
internal write-after-write races (writing the same cached distance to
the same address) that otherwise violate the Go memory model.

This change fixes those races, simplifies the concurrency patterns,
and clarifies goroutine lifetimes. The functions in the imports
package now wait for the goroutines they spawn to finish before
returning, eliminating the need for an awkward test-only mutex that
could otherwise mask real races in the production code paths.

See also:
https://golang.org/wiki/CodeReviewComments#goroutine-lifetimes
https://golang.org/wiki/CodeReviewComments#synchronous-functions

Fixes golang/go#25030.

Change-Id: I8fec735e0d4ff7abab406dea9d0c11d1bd93d775
Reviewed-on: https://go-review.googlesource.com/109156
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2018-04-30 20:17:55 +00:00
..
fix_test.go imports: fix races in findImportGoPath 2018-04-30 20:17:55 +00:00
fix.go imports: fix races in findImportGoPath 2018-04-30 20:17:55 +00:00
imports.go imports: Process should accept nil src 2018-04-12 23:47:31 +00:00
mkindex.go go.tools/imports: move goimports from github to go.tools. 2013-12-17 21:21:03 -05:00
mkstdlib.go imports: update zstdlib to Go 1.10 2018-02-10 03:09:51 +00:00
sortimports.go imports: Remove ancient Go 1.1 compatibility indirections. 2015-12-14 00:47:31 +00:00
zstdlib.go imports: update zstdlib to Go 1.10 2018-02-10 03:09:51 +00:00