diff --git a/future.go b/future.go index 6346b453b..6de2daea4 100644 --- a/future.go +++ b/future.go @@ -84,9 +84,10 @@ func (e errorFuture) Index() uint64 { // deferError can be embedded to allow a future // to provide an error in the future. type deferError struct { - err error - errCh chan error - responded bool + err error + errCh chan error + responded bool + ShutdownCh chan struct{} } func (d *deferError) init() { @@ -103,7 +104,11 @@ func (d *deferError) Error() error { if d.errCh == nil { panic("waiting for response on nil channel") } - d.err = <-d.errCh + select { + case d.err = <-d.errCh: + case <-d.ShutdownCh: + d.err = ErrRaftShutdown + } return d.err } diff --git a/snapshot.go b/snapshot.go index f4c394514..805a09d70 100644 --- a/snapshot.go +++ b/snapshot.go @@ -146,6 +146,7 @@ func (r *Raft) takeSnapshot() (string, error) { // We have to use the future here to safely get this information since // it is owned by the main thread. configReq := &configurationsFuture{} + configReq.ShutdownCh = r.shutdownCh configReq.init() select { case r.configurationsCh <- configReq: