gofinance / ib

Pure Go interface to Interactive Brokers IB API
391 stars 121 forks source link

Prevent data race #36

Open k3a opened 5 years ago

k3a commented 5 years ago

This is finally the correct pull request preventing this data race (using race detector - go run -race ...):

==================
WARNING: DATA RACE
Write at 0x00c0000ba0c8 by goroutine 16:
  github.com/gofinance/ib.(*AbstractManager).startMainLoop.func2()
      /home/kexik/go/pkg/mod/github.com/gofinance/ib@v0.0.0-20190131202149-a7abd0c5d772/manager.go:118 +0x7d

Previous read at 0x00c0000ba0c8 by goroutine 14:
  github.com/gofinance/ib.(*AbstractManager).startMainLoop()
      /home/kexik/go/pkg/mod/github.com/gofinance/ib@v0.0.0-20190131202149-a7abd0c5d772/manager.go:126 +0x2b9

Goroutine 16 (running) created at:
  github.com/gofinance/ib.(*AbstractManager).startMainLoop()
      /home/kexik/go/pkg/mod/github.com/gofinance/ib@v0.0.0-20190131202149-a7abd0c5d772/manager.go:112 +0x1cd

Goroutine 14 (running) created at:
  github.com/gofinance/ib.NewHistoricalDataManager()
      /home/kexik/go/pkg/mod/github.com/gofinance/ib@v0.0.0-20190131202149-a7abd0c5d772/historical_data_manager.go:25 +0x499
==================

Talking about startMainLoop in manager.go:

The solution is actually leaving errors channel living, that is not a problem, it will be garbage-collected after the for loop is broken by any of the other case and the exit from startMainLoop.