Skip to content

Commit

Permalink
Merge pull request hashicorp#92 from abligh/close-transport-on-shutdown
Browse files Browse the repository at this point in the history
Close transport on shutdown
  • Loading branch information
armon committed Mar 17, 2016
2 parents 6b4bd8e + d9a0fd2 commit 3359516
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions future.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 6 additions & 0 deletions inmem_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 3359516

Please sign in to comment.