diff --git a/future.go b/future.go index 854e1ac927b..0b7d4e7975f 100644 --- a/future.go +++ b/future.go @@ -100,6 +100,9 @@ func (s *shutdownFuture) Error() error { for s.raft.getRoutines() > 0 { time.Sleep(5 * time.Millisecond) } + if closeable, ok := s.raft.trans.(WithClose); ok { + closeable.Close() + } return nil } diff --git a/inmem_transport.go b/inmem_transport.go index 994d06d8fad..f32ca49cfd6 100644 --- a/inmem_transport.go +++ b/inmem_transport.go @@ -208,6 +208,12 @@ func (i *InmemTransport) DisconnectAll() { i.pipelines = nil } +// Close is used to permanently disable the transport +func (i *InmemTransport) Close() error { + i.DisconnectAll() + return nil +} + func newInmemPipeline(trans *InmemTransport, peer *InmemTransport, addr string) *inmemPipeline { i := &inmemPipeline{ trans: trans, diff --git a/transport.go b/transport.go index 8928de0c2fc..ebdc8d0ed43 100644 --- a/transport.go +++ b/transport.go @@ -60,6 +60,13 @@ type Transport interface { SetHeartbeatHandler(cb func(rpc RPC)) } +// Close() lives in a separate interface as unfortunately it wasn't in the +// original interface specification. +type WithClose interface { + // Permanently close a transport, stop all go-routines etc + Close() error +} + // AppendPipeline is used for pipelining AppendEntries requests. It is used // to increase the replication throughput by masking latency and better // utilizing bandwidth.