Skip to content

Commit

Permalink
Merge pull request #276 from freeekanayaka/fix-inmem-transport-close-…
Browse files Browse the repository at this point in the history
…race

Check for shutdown in inmemPipeline before sending RPCs
  • Loading branch information
cgbaker authored Oct 31, 2019
2 parents 06fcbee + e290521 commit bc879f9
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion inmem_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type inmemPipeline struct {

shutdown bool
shutdownCh chan struct{}
shutdownLock sync.Mutex
shutdownLock sync.RWMutex
}

type inmemPipelineInflight struct {
Expand Down Expand Up @@ -314,6 +314,17 @@ func (i *inmemPipeline) AppendEntries(args *AppendEntriesRequest, resp *AppendEn
Command: args,
RespChan: respCh,
}

// Check if we have been already shutdown, otherwise the random choose
// made by select statement below might pick consumerCh even if
// shutdownCh was closed.
i.shutdownLock.RLock()
shutdown := i.shutdown
i.shutdownLock.RUnlock()
if shutdown {
return nil, ErrPipelineShutdown
}

select {
case i.peer.consumerCh <- rpc:
case <-timeout:
Expand Down

0 comments on commit bc879f9

Please sign in to comment.