diff --git a/inmem_transport.go b/inmem_transport.go index ce37f63aa..b6b523b1e 100644 --- a/inmem_transport.go +++ b/inmem_transport.go @@ -24,7 +24,7 @@ type inmemPipeline struct { shutdown bool shutdownCh chan struct{} - shutdownLock sync.Mutex + shutdownLock sync.RWMutex } type inmemPipelineInflight struct { @@ -288,6 +288,16 @@ 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() + if i.shutdown { + return nil, ErrPipelineShutdown + } + i.shutdownLock.RUnlock() + select { case i.peer.consumerCh <- rpc: case <-timeout: