From a55b3cc15a6d9bce116a90f33df4bc99d9dd6a10 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sun, 28 Aug 2022 20:31:27 +0200 Subject: tests/matrix: fix data race in TestConcurrentReadWrite Fixes https://github.com/golang/go/issues/54715 Output was: $ go test ./tests/matrix -run TestConcurrentReadWrite -race test_helpers: warning: testParentDir "/tmp/gocryptfs-test-parent-1026" does not reside on ext4, we will miss failures caused by ino reuse PASS PASS ================== WARNING: DATA RACE Write at 0x00c00038a0e0 by goroutine 63: runtime.racewriterange() :1 +0x29 internal/poll.(*FD).Pread() /usr/local/go/src/internal/poll/fd_unix.go:193 +0x169 os.(*File).pread() /usr/local/go/src/os/file_posix.go:40 +0x335 os.(*File).ReadAt() /usr/local/go/src/os/file.go:136 +0x2de github.com/rfjakob/gocryptfs/v2/tests/matrix.TestConcurrentReadWrite.func1() /home/jakob/go/src/github.com/rfjakob/gocryptfs/tests/matrix/concurrency_test.go:40 +0x14b Previous write at 0x00c00038a0e0 by goroutine 61: runtime.racewriterange() :1 +0x29 internal/poll.(*FD).Pread() /usr/local/go/src/internal/poll/fd_unix.go:193 +0x169 os.(*File).pread() /usr/local/go/src/os/file_posix.go:40 +0x335 os.(*File).ReadAt() /usr/local/go/src/os/file.go:136 +0x2de github.com/rfjakob/gocryptfs/v2/tests/matrix.TestConcurrentReadWrite.func1() /home/jakob/go/src/github.com/rfjakob/gocryptfs/tests/matrix/concurrency_test.go:40 +0x14b Goroutine 63 (running) created at: github.com/rfjakob/gocryptfs/v2/tests/matrix.TestConcurrentReadWrite() /home/jakob/go/src/github.com/rfjakob/gocryptfs/tests/matrix/concurrency_test.go:34 +0x31d testing.tRunner() /usr/local/go/src/testing/testing.go:1446 +0x216 testing.(*T).Run.func1() /usr/local/go/src/testing/testing.go:1493 +0x47 Goroutine 61 (running) created at: github.com/rfjakob/gocryptfs/v2/tests/matrix.TestConcurrentReadWrite() /home/jakob/go/src/github.com/rfjakob/gocryptfs/tests/matrix/concurrency_test.go:34 +0x31d testing.tRunner() /usr/local/go/src/testing/testing.go:1446 +0x216 testing.(*T).Run.func1() /usr/local/go/src/testing/testing.go:1493 +0x47 ================== --- FAIL: TestConcurrentReadWrite (0.03s) testing.go:1319: race detected during execution of test FAIL TestMain: matrix[2] = matrix.testcaseMatrix{plaintextnames:false, openssl:"false", aessiv:false, raw64:false, extraArgs:[]string(nil)} failed FAIL github.com/rfjakob/gocryptfs/v2/tests/matrix 0.170s FAIL --- tests/matrix/concurrency_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/matrix/concurrency_test.go b/tests/matrix/concurrency_test.go index d824316..4f060ab 100644 --- a/tests/matrix/concurrency_test.go +++ b/tests/matrix/concurrency_test.go @@ -24,7 +24,6 @@ func TestConcurrentReadWrite(t *testing.T) { } else { f.Close() } - buf := make([]byte, 100) content := []byte("1234567890") threads := 10 loops := 30 @@ -32,6 +31,7 @@ func TestConcurrentReadWrite(t *testing.T) { // Reader thread wg.Add(1) go func() { + buf := make([]byte, 100) fRd, err := os.Open(fn) if err != nil { log.Fatal(err) -- cgit v1.2.3