yudai/gotty · error
failed to authenticate websocket connection
Error message
failed to authenticate websocket connection
What it means
Returned by processWSConn when the very first websocket ReadMessage fails, meaning the client never delivered the initial authentication line — typically a network drop, an immediate disconnect, or a non-websocket client hitting the endpoint. The underlying read error is wrapped for context.
Source
Thrown at server/handlers.go:93
err = server.processWSConn(ctx, conn)
switch err {
case ctx.Err():
closeReason = "cancelation"
case webtty.ErrSlaveClosed:
closeReason = server.factory.Name()
case webtty.ErrMasterClosed:
closeReason = "client"
default:
closeReason = fmt.Sprintf("an error: %s", err)
}
}
}
func (server *Server) processWSConn(ctx context.Context, conn *websocket.Conn) error {
typ, initLine, err := conn.ReadMessage()
if err != nil {
return errors.Wrapf(err, "failed to authenticate websocket connection")
}
if typ != websocket.TextMessage {
return errors.New("failed to authenticate websocket connection: invalid message type")
}
var init InitMessage
err = json.Unmarshal(initLine, &init)
if err != nil {
return errors.Wrapf(err, "failed to authenticate websocket connection")
}
if init.AuthToken != server.options.Credential {
return errors.New("failed to authenticate websocket connection")
}
queryPath := "?"
if server.options.PermitArguments && init.Arguments != "" {
queryPath = init.Arguments
}View on GitHub (pinned to a080c85cbc)
Solutions
- Verify the client is a real websocket peer speaking the correct subprotocol/URL before the handshake
- Check for intermediaries (proxies, load balancers) that truncate or buffer the first frame
- Inspect the wrapped error (close frame, timeout, EOF) to distinguish client abort from transport failure
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at server/handlers.go:93 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- Authentication and authorization failures — expired tokens, bad credentials, and missing scopes.
AI-assisted analysis of yudai/gotty@a080c85cbc (2026-09-02).
Data as JSON: /api/errors/79780ea23b92c64b.
Report an issue: GitHub.