Skip to content

Commit

Permalink
Close multiplexer when context is cancelled
Browse files Browse the repository at this point in the history
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 hashicorp#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 hashicorp#4413
  • Loading branch information
Xopherus committed Aug 13, 2018
1 parent 75c5fb4 commit 132fcbb
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions nomad/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 132fcbb

Please sign in to comment.