{"record":{"id":"ec81e56ff3b0df0d","repo":"XTLS/Xray-core","slug":"failed-to-write-back-ok-response","errorCode":null,"errorMessage":"failed to write back OK response","messagePattern":"failed to write back OK response","errorType":"exception","errorClass":"errors.Error","httpStatus":null,"severity":"error","filePath":"proxy/http/server.go","lineNumber":179,"sourceCode":"\t}\n\n\tkeepAlive := (strings.TrimSpace(strings.ToLower(request.Header.Get(\"Proxy-Connection\"))) == \"keep-alive\")\n\n\terr = s.handlePlainHTTP(ctx, request, conn, dest, dispatcher)\n\tif err == errWaitAnother {\n\t\tif keepAlive {\n\t\t\tgoto Start\n\t\t}\n\t\terr = nil\n\t}\n\n\treturn err\n}\n\nfunc (s *Server) handleConnect(ctx context.Context, _ *http.Request, buffer *bufio.Reader, conn stat.Connection, dest net.Destination, dispatcher routing.Dispatcher, inbound *session.Inbound) error {\n\t_, err := conn.Write([]byte(\"HTTP/1.1 200 Connection established\\r\\n\\r\\n\"))\n\tif err != nil {\n\t\treturn errors.New(\"failed to write back OK response\").Base(err)\n\t}\n\n\treader := buf.NewReader(conn)\n\tif buffer.Buffered() > 0 {\n\t\tpayload, err := buf.ReadFrom(io.LimitReader(buffer, int64(buffer.Buffered())))\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\treader = &buf.BufferedReader{Reader: reader, Buffer: payload}\n\t\tbuffer = nil\n\t}\n\n\tif inbound.CanSpliceCopy == 2 {\n\t\tinbound.CanSpliceCopy = 1\n\t}\n\tif err := dispatcher.DispatchLink(\n\t\tctx, dest, &transport.Link{\n\t\t\tReader: reader,","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/proxy/http/server.go#L161-L197","documentation":"Error \"failed to write back OK response\" thrown in XTLS/Xray-core.","triggerScenarios":"Thrown at proxy/http/server.go:179 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}