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
This commit is contained in:
parent
2a3eac1ce3
commit
8d747578e8
10
nomad/rpc.go
10
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 {
|
||||
|
|
Loading…
Reference in New Issue