Skip to content

Commit

Permalink
chain: resolve data race in sequential start stop test
Browse files Browse the repository at this point in the history
Resolve the data race in the sequential start stop unit test
by ensuring that each goroutine launched in the Start method
is properly accounted for in the client's waitgroup.
  • Loading branch information
MStreet3 committed Nov 26, 2022
1 parent 531c49b commit baead51
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions chain/neutrino.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,26 @@ func (s *NeutrinoClient) Start() error {
s.clientMtx.Lock()
defer s.clientMtx.Unlock()
if !s.started {
// Reset the client state.
s.enqueueNotification = make(chan interface{})
s.dequeueNotification = make(chan interface{})
s.currentBlock = make(chan *waddrmgr.BlockStamp)
s.quit = make(chan struct{})
s.started = true

// Go place a ClientConnected notification onto the queue.
s.wg.Add(1)
go func() {
defer s.wg.Done()

select {
case s.enqueueNotification <- ClientConnected{}:
case <-s.quit:
}
}()

// Go launch the notification handler.
s.wg.Add(1)
go s.notificationHandler()
}
return nil
Expand Down

0 comments on commit baead51

Please sign in to comment.