Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

agent: ignore websocket statuses 1000, 1001 and 1005 correctly #19172

Merged
merged 2 commits into from
Nov 27, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) })
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting the following when stopping/cancelling an action from the UI on this branch:

{
  "@level": "info",
  "@message": "task exec session starting",
  "@module": "client",
  "@timestamp": "2023-11-26T23:38:31.084156-05:00",
  "action": "echo time",
  "alloc_id": "faa9dbd2-828f-e586-a04c-b0e7923073d9",
  "command": null,
  "exec_id": "f45b2b00-adc1-c9da-252e-01ec12181de5",
  "task": "task",
  "tty": true
}
{
  "@level": "info",
  "@message": "task exec session ended with an error",
  "@module": "client",
  "@timestamp": "2023-11-26T23:38:35.181010-05:00",
  "code": 500,
  "error": "msgpack encode error: io: read/write on closed pipe"
}
{
  "@level": "debug",
  "@message": "alloc exec channel closed with error",
  "@module": "http",
  "@timestamp": "2023-11-26T23:38:35.181245-05:00",
  "error": "websocket: close 1005 (no status)"
}
{
  "@level": "debug",
  "@message": "request complete",
  "@module": "http",
  "@timestamp": "2023-11-26T23:38:35.181884-05:00",
  "duration": 4105460042,
  "method": "GET",
  "path": "/v1/job/actions-demo/action?namespace=default&action=echo%20time&allocID=faa9dbd2-828f-e586-a04c-b0e7923073d9&task=task&group=group&tty=true&ws_handshake=true"
}

This is a nice improvement over what I used to get:

{
  "@level": "info",
  "@message": "task exec session starting",
  "@module": "client",
  "@timestamp": "2023-11-26T23:43:43.882529-05:00",
  "action": "echo time",
  "alloc_id": "a190347c-dd97-27e5-bb9a-5aed4dff33cb",
  "command": null,
  "exec_id": "f120709a-6adc-535c-4fe5-722490312ed3",
  "task": "task",
  "tty": true
}
{
  "@level": "info",
  "@message": "task exec session ended with an error",
  "@module": "client",
  "@timestamp": "2023-11-26T23:43:47.969123-05:00",
  "code": 500,
  "error": "msgpack encode error: io: read/write on closed pipe"
}
{
  "@level": "debug",
  "@message": "alloc exec channel closed with error",
  "@module": "http",
  "@timestamp": "2023-11-26T23:43:47.969413-05:00",
  "error": "websocket: close 1005 (no status)"
}
{
  "@level": "error",
  "@message": "request failed",
  "@module": "http",
  "@timestamp": "2023-11-26T23:43:47.969760-05:00",
  "code": 500,
  "error": "websocket: close 1005 (no status)",
  "method": "GET",
  "path": "/v1/job/actions-demo/action?namespace=default&action=echo%20time&allocID=a190347c-dd97-27e5-bb9a-5aed4dff33cb&task=task&group=group&tty=true&ws_handshake=true"
}

return err == io.EOF ||
err == io.ErrClosedPipe ||
strings.Contains(err.Error(), "closed") ||
Expand Down