Go can detect race conditions by giving the -race option.
According to the results, there is apparently a data race for virtio net in
cdd468358729 ("Merge pull request #135 from bobuhiro11/add_travis_retry").
We may need to implement some locking mechanism (e.g. sync.Mutex) for virtio data.
ubuntu2004thinkpad:~/gokvm$ sudo env "PATH=$PATH" go test ./machine/... -race
...
==================
WARNING: DATA RACE
Read at 0x00c00038e048 by goroutine 14:
github.com/bobuhiro11/gokvm/virtio.(*Net).IOInHandler()
<autogenerated>:1 +0x85
github.com/bobuhiro11/gokvm/pci.Device.IOInHandler-fm()
<autogenerated>:1 +0x81
github.com/bobuhiro11/gokvm/machine.(*Machine).RunOnce()
/home/bobuhiro11/gokvm/machine/machine.go:683 +0x9a2
github.com/bobuhiro11/gokvm/machine.(*Machine).RunInfiniteLoop()
/home/bobuhiro11/gokvm/machine/machine.go:648 +0xaa
github.com/bobuhiro11/gokvm/machine_test.testNewAndLoadLinux.func1()
/home/bobuhiro11/gokvm/machine/machine_test.go:63 +0x44
Previous write at 0x00c00038e048 by goroutine 12:
github.com/bobuhiro11/gokvm/virtio.(*Net).Rx()
/home/bobuhiro11/gokvm/virtio/net.go:169 +0x335
github.com/bobuhiro11/gokvm/virtio.(*Net).RxThreadEntry()
/home/bobuhiro11/gokvm/virtio/net.go:101 +0x84
github.com/bobuhiro11/gokvm/machine.(*Machine).AddTapIf.func2()
/home/bobuhiro11/gokvm/machine/machine.go:196 +0x39
Goroutine 14 (running) created at:
github.com/bobuhiro11/gokvm/machine_test.testNewAndLoadLinux()
/home/bobuhiro11/gokvm/machine/machine_test.go:62 +0x989
github.com/bobuhiro11/gokvm/machine_test.TestNewAndLoadLinuxWithBzImage()
/home/bobuhiro11/gokvm/machine/machine_test.go:99 +0x71
testing.tRunner()
/home/bobuhiro11/.goenv/versions/1.19.0/src/testing/testing.go:1446 +0x216
testing.(*T).Run.func1()
/home/bobuhiro11/.goenv/versions/1.19.0/src/testing/testing.go:1493 +0x47
Goroutine 12 (running) created at:
github.com/bobuhiro11/gokvm/machine.(*Machine).AddTapIf()
/home/bobuhiro11/gokvm/machine/machine.go:196 +0x1b3
github.com/bobuhiro11/gokvm/machine_test.testNewAndLoadLinux()
/home/bobuhiro11/gokvm/machine/machine_test.go:28 +0x255
github.com/bobuhiro11/gokvm/machine_test.TestNewAndLoadLinuxWithBzImage()
/home/bobuhiro11/gokvm/machine/machine_test.go:99 +0x71
testing.tRunner()
/home/bobuhiro11/.goenv/versions/1.19.0/src/testing/testing.go:1446 +0x216
testing.(*T).Run.func1()
/home/bobuhiro11/.goenv/versions/1.19.0/src/testing/testing.go:1493 +0x47
==================
Go can detect race conditions by giving the
-race
option. According to the results, there is apparently a data race for virtio net in cdd468358729 ("Merge pull request #135 from bobuhiro11/add_travis_retry").We may need to implement some locking mechanism (e.g.
sync.Mutex
) for virtio data.