Skip to content

Commit 2e99741

Browse files
futures can react to shutdown (hashicorp#390)
1 parent 9a647f6 commit 2e99741

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

future.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@ func (e errorFuture) Index() uint64 {
8484
// deferError can be embedded to allow a future
8585
// to provide an error in the future.
8686
type deferError struct {
87-
err error
88-
errCh chan error
89-
responded bool
87+
err error
88+
errCh chan error
89+
responded bool
90+
ShutdownCh chan struct{}
9091
}
9192

9293
func (d *deferError) init() {
@@ -103,7 +104,11 @@ func (d *deferError) Error() error {
103104
if d.errCh == nil {
104105
panic("waiting for response on nil channel")
105106
}
106-
d.err = <-d.errCh
107+
select {
108+
case d.err = <-d.errCh:
109+
case <-d.ShutdownCh:
110+
d.err = ErrRaftShutdown
111+
}
107112
return d.err
108113
}
109114

snapshot.go

+1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ func (r *Raft) takeSnapshot() (string, error) {
146146
// We have to use the future here to safely get this information since
147147
// it is owned by the main thread.
148148
configReq := &configurationsFuture{}
149+
configReq.ShutdownCh = r.shutdownCh
149150
configReq.init()
150151
select {
151152
case r.configurationsCh <- configReq:

0 commit comments

Comments
 (0)