{"record":{"id":"79780ea23b92c64b","repo":"yudai/gotty","slug":"failed-to-authenticate-websocket-connection","errorCode":null,"errorMessage":"failed to authenticate websocket connection","messagePattern":"failed to authenticate websocket connection","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/handlers.go","lineNumber":93,"sourceCode":"\t\terr = server.processWSConn(ctx, conn)\n\n\t\tswitch err {\n\t\tcase ctx.Err():\n\t\t\tcloseReason = \"cancelation\"\n\t\tcase webtty.ErrSlaveClosed:\n\t\t\tcloseReason = server.factory.Name()\n\t\tcase webtty.ErrMasterClosed:\n\t\t\tcloseReason = \"client\"\n\t\tdefault:\n\t\t\tcloseReason = fmt.Sprintf(\"an error: %s\", err)\n\t\t}\n\t}\n}\n\nfunc (server *Server) processWSConn(ctx context.Context, conn *websocket.Conn) error {\n\ttyp, initLine, err := conn.ReadMessage()\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"failed to authenticate websocket connection\")\n\t}\n\tif typ != websocket.TextMessage {\n\t\treturn errors.New(\"failed to authenticate websocket connection: invalid message type\")\n\t}\n\n\tvar init InitMessage\n\terr = json.Unmarshal(initLine, &init)\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"failed to authenticate websocket connection\")\n\t}\n\tif init.AuthToken != server.options.Credential {\n\t\treturn errors.New(\"failed to authenticate websocket connection\")\n\t}\n\n\tqueryPath := \"?\"\n\tif server.options.PermitArguments && init.Arguments != \"\" {\n\t\tqueryPath = init.Arguments\n\t}","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/yudai/gotty/blob/a080c85cbc59226c94c6941ad8c395232d72d517/server/handlers.go#L75-L111","documentation":"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.","triggerScenarios":"Thrown at server/handlers.go:93 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a080c85cbc59226c94c6941ad8c395232d72d517","analyzedAt":"2026-09-02T16:42:38.150Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}