Skip to content

Commit

Permalink
agent: ignore websocket statuses 1000, 1001 and 1005 correctly (#19172)
Browse files Browse the repository at this point in the history
These are "close" messages and not actual errors.
  • Loading branch information
pkazmierczak authored Nov 27, 2023
1 parent fb14c2b commit 742651f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/19172.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
agent: Correct websocket status code handling
```
10 changes: 10 additions & 0 deletions command/agent/alloc_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"io"
"net"
"net/http"
"slices"
"strconv"
"strings"

Expand Down Expand Up @@ -671,6 +672,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") ||
Expand Down

0 comments on commit 742651f

Please sign in to comment.