Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data race when calling acceptor.Stop() immediately after acceptor.Start() #681

Open
vihaanthora opened this issue Nov 26, 2024 · 0 comments

Comments

@vihaanthora
Copy link

Description

When calling acceptor.Stop() immediately after acceptor.Start(), there appears to be a data race for the sync.Once variable in session stopOnce when these two functions are called in succession. This issue was not present in v0.7.0.

Steps To Reproduce

func TestQuickFIXAcceptor(t *testing.T) {
	// Create a QuickFIX configuration file in memory for the acceptor
	cfg := `
[DEFAULT]
ConnectionType=acceptor
ReconnectInterval=5
StartTime=00:00:00
EndTime=23:59:59
HeartBtInt=30
SocketAcceptPort=5000

[SESSION]
BeginString=FIX.4.2
SenderCompID=SERVER
TargetCompID=CLIENT
`

	// Parse the settings
	settings, err := quickfix.ParseSettings(strings.NewReader(cfg))
	require.NoError(t, err)

	// Create a minimal application that implements the Application interface
	app := Application{}

	// Create the store and log factories
	storeFactory := quickfix.NewMemoryStoreFactory()
	logFactory := quickfix.NewScreenLogFactory()

	// Create the acceptor
	acceptor, err := quickfix.NewAcceptor(&app, storeFactory, settings, logFactory)
	require.NoError(t, err)

	// Start the acceptor
	err = acceptor.Start()
	require.NoError(t, err)

	// Stop the acceptor
	acceptor.Stop()
}

Race Detector Error Stack

=== RUN   TestQuickFIXAcceptor
<2024-11-26 12:56:00.737010131 +0000 UTC, FIX.4.2:SERVER->CLIENT, event>
  (Created session)
==================
WARNING: DATA RACE
Read at 0x00c0001e0134 by goroutine 25:
  sync/atomic.LoadInt32()
      /usr/local/go/src/runtime/race_amd64.s:202 +0xb
  sync/atomic.LoadUint32()
      <autogenerated>:1 +0x10
  sync.(*Once).Do()
      /usr/local/go/src/sync/once.go:63 +0x30
  github.com/quickfixgo/quickfix.(*session).stop()
      ~/go/pkg/mod/github.com/quickfixgo/[email protected]/session.go:96 +0x2d1
  github.com/quickfixgo/quickfix.(*Acceptor).Stop()
      ~/go/pkg/mod/github.com/quickfixgo/[email protected]/acceptor.go:148 +0x27a
  github.com/quickfix-test/pkg/fix.TestQuickFIXAcceptor()
      ~/Projects/quickfix-test/go/pkg/fix/engine_test.go:90 +0x1b7
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1689 +0x21e
  testing.(*T).Run.gowrap1()
      /usr/local/go/src/testing/testing.go:1742 +0x44

Previous write at 0x00c0001e0134 by goroutine 26:
  github.com/quickfixgo/quickfix.(*session).run()
      ~/go/pkg/mod/github.com/quickfixgo/[email protected]/session.go:866 +0x4f
  github.com/quickfixgo/quickfix.(*Acceptor).Start.func1()
      ~/go/pkg/mod/github.com/quickfixgo/[email protected]/acceptor.go:115 +0x2f
  github.com/quickfixgo/quickfix.(*Acceptor).Start.gowrap1()
      ~/go/pkg/mod/github.com/quickfixgo/[email protected]/acceptor.go:117 +0x41

Goroutine 25 (running) created at:
  testing.(*T).Run()
      /usr/local/go/src/testing/testing.go:1742 +0x825
  testing.runTests.func1()
      /usr/local/go/src/testing/testing.go:2161 +0x85
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1689 +0x21e
  testing.runTests()
      /usr/local/go/src/testing/testing.go:2159 +0x8be
  testing.(*M).Run()
      /usr/local/go/src/testing/testing.go:2027 +0xf17
  main.main()
      _testmain.go:165 +0x2bd

Goroutine 26 (running) created at:
  github.com/quickfixgo/quickfix.(*Acceptor).Start()
      ~/go/pkg/mod/github.com/quickfixgo/[email protected]/acceptor.go:114 +0x19d8
  github.com/quickfix-test/pkg/fix.TestQuickFIXAcceptor()
      ~/Projects/quickfix-test/go/pkg/fix/engine_test.go:86 +0x18e
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1689 +0x21e
  testing.(*T).Run.gowrap1()
      /usr/local/go/src/testing/testing.go:1742 +0x44
==================
==================
WARNING: DATA RACE
Write at 0x00c0001e0138 by goroutine 25:
  sync/atomic.CompareAndSwapInt32()
      /usr/local/go/src/runtime/race_amd64.s:310 +0xb
  sync/atomic.CompareAndSwapInt32()
      <autogenerated>:1 +0x18
  sync.(*Once).doSlow()
      /usr/local/go/src/sync/once.go:70 +0x51
  sync.(*Once).Do()
      /usr/local/go/src/sync/once.go:65 +0x44
  github.com/quickfixgo/quickfix.(*session).stop()
      ~/go/pkg/mod/github.com/quickfixgo/[email protected]/session.go:96 +0x2d1
  github.com/quickfixgo/quickfix.(*Acceptor).Stop()
      ~/go/pkg/mod/github.com/quickfixgo/[email protected]/acceptor.go:148 +0x27a
  github.com/quickfix-test/pkg/fix.TestQuickFIXAcceptor()
      ~/Projects/quickfix-test/go/pkg/fix/engine_test.go:90 +0x1b7
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1689 +0x21e
  testing.(*T).Run.gowrap1()
      /usr/local/go/src/testing/testing.go:1742 +0x44

Previous write at 0x00c0001e0138 by goroutine 26:
  github.com/quickfixgo/quickfix.(*session).run()
      ~/go/pkg/mod/github.com/quickfixgo/[email protected]/session.go:866 +0x4f
  github.com/quickfixgo/quickfix.(*Acceptor).Start.func1()
      ~/go/pkg/mod/github.com/quickfixgo/[email protected]/acceptor.go:115 +0x2f
  github.com/quickfixgo/quickfix.(*Acceptor).Start.gowrap1()
      ~/go/pkg/mod/github.com/quickfixgo/[email protected]/acceptor.go:117 +0x41

Goroutine 25 (running) created at:
  testing.(*T).Run()
      /usr/local/go/src/testing/testing.go:1742 +0x825
  testing.runTests.func1()
      /usr/local/go/src/testing/testing.go:2161 +0x85
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1689 +0x21e
  testing.runTests()
      /usr/local/go/src/testing/testing.go:2159 +0x8be
  testing.(*M).Run()
      /usr/local/go/src/testing/testing.go:2027 +0xf17
  main.main()
      _testmain.go:165 +0x2bd

Goroutine 26 (running) created at:
  github.com/quickfixgo/quickfix.(*Acceptor).Start()
      ~/go/pkg/mod/github.com/quickfixgo/[email protected]/acceptor.go:114 +0x19d8
  github.com/quickfix-test/pkg/fix.TestQuickFIXAcceptor()
      ~/Projects/quickfix-test/go/pkg/fix/engine_test.go:86 +0x18e
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1689 +0x21e
  testing.(*T).Run.gowrap1()
      /usr/local/go/src/testing/testing.go:1742 +0x44
==================
    ~/Projects/quickfix-test/go/pkg/fix/testing.go:1398: race detected during execution of test
--- FAIL: TestQuickFIXAcceptor (0.27s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant