From 98ac3036fe17427f4361bcb9315b8dc8eb3c0b3f Mon Sep 17 00:00:00 2001 From: Piotr Kazmierczak <470696+pkazmierczak@users.noreply.github.com> Date: Mon, 27 Nov 2023 08:33:08 +0000 Subject: [PATCH] backport of commit 742651f2f715af69dda77b8ffb3af3d114e25ac2 --- .changelog/19172.txt | 3 +++ command/agent/alloc_endpoint.go | 10 ++++++++++ 2 files changed, 13 insertions(+) create mode 100644 .changelog/19172.txt diff --git a/.changelog/19172.txt b/.changelog/19172.txt new file mode 100644 index 00000000000..15443ba4b67 --- /dev/null +++ b/.changelog/19172.txt @@ -0,0 +1,3 @@ +```release-note:bug +agent: Correct websocket status code handling +``` diff --git a/command/agent/alloc_endpoint.go b/command/agent/alloc_endpoint.go index e17369a4c80..d63f5777e93 100644 --- a/command/agent/alloc_endpoint.go +++ b/command/agent/alloc_endpoint.go @@ -7,6 +7,7 @@ import ( "io" "net" "net/http" + "slices" "strconv" "strings" @@ -668,6 +669,15 @@ func isClosedError(err error) bool { return false } + // check if the websocket "error" is one of the benign "close" status codes + if codedErr, ok := err.(HTTPCodedError); ok { + return slices.ContainsFunc([]string{ + "close 1000", // CLOSE_NORMAL + "close 1001", // CLOSE_GOING_AWAY + "close 1005", // CLOSED_NO_STATUS + }, func(s string) bool { return strings.Contains(codedErr.Error(), s) }) + } + return err == io.EOF || err == io.ErrClosedPipe || strings.Contains(err.Error(), "closed") ||