Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix a data race when Cancel results in an os.RemoveAll error
The data race below was caught by a test in a third-party project: WARNING: DATA RACE Write at 0x00c0001564b8 by goroutine 27: github.com/chromedp/chromedp.(*ExecAllocator).Allocate.func2() github.com/chromedp/chromedp@v0.5.4-0.20200615134453-af6afb6eba43/allocate.go:209 +0x109 Previous read at 0x00c0001564b8 by goroutine 40: github.com/chromedp/chromedp.Cancel() github.com/chromedp/chromedp@v0.5.4-0.20200615134453-af6afb6eba43/chromedp.go:227 +0x1e8 The cause was that c.cancelErr can be modified while c.allocated hasn't been closed, and Cancel can end up reading c.cancelErr before the channel is closed if the context is canceled. Fix that mistake. Before, the third-party test failed 4 times out of 600 with the stress tool and -race. After the fix, we got to 1000 runs with no failures.
- Loading branch information