From 4f57e06957424df2da508ae44882e2d0812abc5c Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Mon, 24 May 2021 09:46:45 -0400 Subject: [PATCH] agent: surface websocket errors in logs The websocket interface used for `alloc exec` has to silently drop client send errors because otherwise those errors would interleave with the streamed output. But we may be able to surface errors that cause terminated websockets a little better in the HTTP server logs. --- command/agent/alloc_endpoint.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/command/agent/alloc_endpoint.go b/command/agent/alloc_endpoint.go index 208651448..e8eda6025 100644 --- a/command/agent/alloc_endpoint.go +++ b/command/agent/alloc_endpoint.go @@ -556,10 +556,14 @@ func (s *HTTPServer) execStreamImpl(ws *websocket.Conn, args *cstructs.AllocExec handler(handlerPipe) // stop streaming background goroutines for streaming - but not websocket activity cancel() - // retreieve any error and/or wait until goroutine stop and close errCh connection before + // retrieve any error and/or wait until goroutine stop and close errCh connection before // closing websocket connection codedErr := <-errCh + // we won't return an error on ws close, but at least make it available in + // the logs so we can trace spurious disconnects + s.logger.Debug("alloc exec channel closed with error", "error", codedErr) + if isClosedError(codedErr) { codedErr = nil } else if codedErr != nil {