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.

Add a TODO to shutdown the rescan goroutine when the Stop
method is called.
  • Loading branch information
MStreet3 committed Dec 2, 2022
1 parent 90844c7 commit 47929e7
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions chain/neutrino.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,36 @@ 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
}

// Stop replicates the RPC client's Stop method.
//
// TODO(mstreet3): The Stop method does not cancel the long-running rescan
// goroutine. This is a memory leak. Stop should shutdown the rescan goroutine
// and reset the scanning state of the NeutrinoClient to false.
func (s *NeutrinoClient) Stop() {
s.clientMtx.Lock()
defer s.clientMtx.Unlock()
Expand Down

0 comments on commit 47929e7

Please sign in to comment.