stellar-deprecated / starlight

Layer 2 payment channel protocol for the Stellar network.
Apache License 2.0
41 stars 9 forks source link

sdk/agent: data race in test #422

Open leighmcculloch opened 2 years ago

leighmcculloch commented 2 years ago

There's a data race in this concurrency test. This was seen in an CI run.

==================
WARNING: DATA RACE
Write at 0x00c0002693c3 by goroutine 13:
  testing.tRunner.func1()
      /opt/hostedtoolcache/go/1.17.2/x64/src/testing/testing.go:1246 +0x584
  testing.tRunner()
      /opt/hostedtoolcache/go/1.17.2/x64/src/testing/testing.go:1265 +0x268
  testing.(*T).Run·dwrap·21()
      /opt/hostedtoolcache/go/1.17.2/x64/src/testing/testing.go:1306 +0x47

Previous read at 0x00c0002693c3 by goroutine 15:
  testing.(*common).logDepth()
      /opt/hostedtoolcache/go/1.17.2/x64/src/testing/testing.go:768 +0xc4
  testing.(*common).log()
      /opt/hostedtoolcache/go/1.17.2/x64/src/testing/testing.go:761 +0x6e
  testing.(*common).Logf()
      /opt/hostedtoolcache/go/1.17.2/x64/src/testing/testing.go:807 +0x14
  github.com/stellar/starlight/sdk/agent.TestAgent_concurrency.func9()
      /home/runner/work/starlight/starlight/sdk/agent/agent_test.go:577 +0xc5

Goroutine 13 (running) created at:
  testing.(*T).Run()
      /opt/hostedtoolcache/go/1.17.2/x64/src/testing/testing.go:1306 +0x726
  testing.runTests.func1()
      /opt/hostedtoolcache/go/1.17.2/x64/src/testing/testing.go:1598 +0x99
  testing.tRunner()
      /opt/hostedtoolcache/go/1.17.2/x64/src/testing/testing.go:1259 +0x22f
  testing.runTests()
      /opt/hostedtoolcache/go/1.17.2/x64/src/testing/testing.go:1596 +0x7ca
  testing.(*M).Run()
      /opt/hostedtoolcache/go/1.17.2/x64/src/testing/testing.go:1504 +0x9d1
  main.main()
      _testmain.go:45 +0x22b

Goroutine 15 (running) created at:
  github.com/stellar/starlight/sdk/agent.TestAgent_concurrency()
      /home/runner/work/starlight/starlight/sdk/agent/agent_test.go:574 +0x13e4
  testing.tRunner()
      /opt/hostedtoolcache/go/1.17.2/x64/src/testing/testing.go:1259 +0x22f
  testing.(*T).Run·dwrap·21()
      /opt/hostedtoolcache/go/1.17.2/x64/src/testing/testing.go:1306 +0x47
==================
=== CONT  
    testing.go:1152: race detected during execution of test
FAIL
FAIL    github.com/stellar/starlight/sdk/agent  0.374s
leighmcculloch commented 2 years ago

One of the lines noted in the output is a call to t.Logf, so maybe it's a bad idea for us to be calling that function inside the go routine. I was under the impression calls to the t were behind a mutex, and so safe to do concurrently, but this error suggests not so.