close raft long-lived connections

This commit is contained in:
Chelsea Holland Komlo 2017-11-21 14:45:50 -05:00
parent acd3d1b162
commit dfb6a3d9a8
3 changed files with 19 additions and 4 deletions

View File

@ -51,7 +51,7 @@ func (l *RaftLayer) Handoff(c net.Conn, ctx context.Context) error {
case <-l.closeCh: case <-l.closeCh:
return fmt.Errorf("Raft RPC layer closed") return fmt.Errorf("Raft RPC layer closed")
case <-ctx.Done(): case <-ctx.Done():
return fmt.Errorf("[INFO] nomad.rpc: Closing server RPC connection") return fmt.Errorf("[INFO] nomad.rpc: Closing raft RPC connection")
} }
} }

View File

@ -405,14 +405,16 @@ func (s *Server) ReloadTLSConnections(newTLSConfig *config.TLSConfig) error {
} }
s.rpcListener = list s.rpcListener = list
wrapper := tlsutil.RegionSpecificWrapper(s.config.Region, tlsWrap)
s.raftLayer.ReloadTLS(wrapper)
s.raftTransport.Reload()
time.Sleep(500 * time.Millisecond)
// reinitialize the cancel context // reinitialize the cancel context
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
s.rpcCancel = cancel s.rpcCancel = cancel
go s.listen(ctx) go s.listen(ctx)
wrapper := tlsutil.RegionSpecificWrapper(s.config.Region, tlsWrap)
s.raftLayer.ReloadTLS(wrapper)
s.logger.Printf("[INFO] nomad: finished reloading server connections") s.logger.Printf("[INFO] nomad: finished reloading server connections")
return nil return nil
} }

View File

@ -177,6 +177,19 @@ func (n *NetworkTransport) Close() error {
return nil return nil
} }
func (n *NetworkTransport) Reload() {
n.shutdownLock.Lock()
defer n.shutdownLock.Unlock()
if !n.shutdown {
close(n.shutdownCh)
n.shutdown = true
}
time.Sleep(3 * time.Second)
n.shutdownCh = make(chan struct{})
}
// Consumer implements the Transport interface. // Consumer implements the Transport interface.
func (n *NetworkTransport) Consumer() <-chan RPC { func (n *NetworkTransport) Consumer() <-chan RPC {
return n.consumeCh return n.consumeCh