From 8d747578e81abd68e0e955f39a6f3d298dfaf8af Mon Sep 17 00:00:00 2001 From: Xopherus Date: Fri, 10 Aug 2018 15:06:20 -0400 Subject: [PATCH] Close multiplexer when context is cancelled Multiplexer continues to create rpc connections even when the context which is passed to the underlying rpc connections is cancelled by the server. This was causing #4413 - when a SIGHUP causes everything to reload, it uses context to cancel the underlying http/rpc connections so that they may come up with the new configuration. The multiplexer was not being cancelled properly so it would continue to create rpc connections and constantly fail, causing communication issues with other nomad agents. Fixes #4413 --- nomad/rpc.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/nomad/rpc.go b/nomad/rpc.go index 83238630c..2d6302afa 100644 --- a/nomad/rpc.go +++ b/nomad/rpc.go @@ -208,6 +208,11 @@ func (s *Server) handleMultiplex(ctx context.Context, conn net.Conn, rpcCtx *RPC s.setupRpcServer(rpcServer, rpcCtx) for { + // stop handling connections if context was cancelled + if ctx.Err() != nil { + return + } + sub, err := server.Accept() if err != nil { if err != io.EOF { @@ -311,6 +316,11 @@ func (s *Server) handleMultiplexV2(ctx context.Context, conn net.Conn, rpcCtx *R s.setupRpcServer(rpcServer, rpcCtx) for { + // stop handling connections if context was cancelled + if ctx.Err() != nil { + return + } + // Accept a new stream sub, err := server.Accept() if err != nil {