From ab4b42f4f40e756a2618ac4959f02aeb3e680572 Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Mon, 24 May 2021 13:37:23 -0400 Subject: [PATCH] exec: http: close websocket connection gracefully In this loop, we ought to close the websocket connection gracefully when the StreamErrWrapper reaches EOF. Previously, it's possible that that we drop the last few events or skip sending the websocket closure. If `handler(handlerPipe)` returns and `cancel` is called, before the loop here completes processing streaming events, the loop exits prematurely without propagating the last few events. Instead here, the loop continues until we hit `httpPipe` EOF (through `decoder.Decode`), to ensure we process the events to completion. --- command/agent/alloc_endpoint.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/command/agent/alloc_endpoint.go b/command/agent/alloc_endpoint.go index e8eda6025..d1a7e210c 100644 --- a/command/agent/alloc_endpoint.go +++ b/command/agent/alloc_endpoint.go @@ -515,13 +515,6 @@ func (s *HTTPServer) execStreamImpl(ws *websocket.Conn, args *cstructs.AllocExec go forwardExecInput(encoder, ws, errCh) for { - select { - case <-ctx.Done(): - errCh <- nil - return - default: - } - var res cstructs.StreamErrWrapper err := decoder.Decode(&res) if isClosedError(err) {