{"record":{"id":"d1fa979b81e2bbbf","repo":"XTLS/Xray-core","slug":"connection-ends-d1fa97","errorCode":null,"errorMessage":"connection ends","messagePattern":"connection ends","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"proxy/shadowsocks/client.go","lineNumber":150,"sourceCode":"\t\t\t}\n\n\t\t\treturn buf.Copy(link.Reader, bodyWriter, buf.UpdateActivity(timer))\n\t\t}\n\n\t\tresponseDone := func() error {\n\t\t\tdefer timer.SetTimeout(sessionPolicy.Timeouts.UplinkOnly)\n\n\t\t\tresponseReader, err := ReadTCPResponse(user, conn)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\n\t\t\treturn buf.Copy(responseReader, link.Writer, buf.UpdateActivity(timer))\n\t\t}\n\n\t\tresponseDoneAndCloseWriter := task.OnSuccess(responseDone, task.Close(link.Writer))\n\t\tif err := task.Run(ctx, requestDone, responseDoneAndCloseWriter); err != nil {\n\t\t\treturn errors.New(\"connection ends\").Base(err)\n\t\t}\n\n\t\treturn nil\n\t}\n\n\tif request.Command == protocol.RequestCommandUDP {\n\n\t\trequestDone := func() error {\n\t\t\tdefer timer.SetTimeout(sessionPolicy.Timeouts.DownlinkOnly)\n\n\t\t\twriter := &UDPWriter{\n\t\t\t\tWriter:  conn,\n\t\t\t\tRequest: request,\n\t\t\t}\n\n\t\t\tif err := buf.Copy(link.Reader, writer, buf.UpdateActivity(timer)); err != nil {\n\t\t\t\treturn errors.New(\"failed to transport all UDP request\").Base(err)\n\t\t\t}","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/proxy/shadowsocks/client.go#L132-L168","documentation":"Generic wrapper returned when task.Run finishes the TCP session and either the request goroutine (client→server relay) or the response goroutine (server→client relay, plus writer close) exited with an error. The Base error carries the real cause — commonly one of the sibling errors (failed to write request / payload) or a response read failure. Seeing this alone means the actual failure is one level down in the error chain.","triggerScenarios":"Any TCP Shadowsocks client session where requestDone or responseDoneAndCloseWriter returns non-nil: mid-stream connection reset in either direction, ReadTCPResponse failing to parse the response header, or context cancellation while relaying.","commonSituations":"Server drops the session mid-transfer (idle timeout, restart); destination site resets the tunnelled connection; user cancels the request (browser stop / app close) which cancels ctx; response header decrypt failure after server-side key rotation.","solutions":["Inspect the wrapped (Base) error in the log line — it names which direction and which operation actually failed; fix that root cause.","If it is io.EOF/context.Canceled on user abort, treat as normal session end, not a fault.","For mid-stream resets, verify server stability and policy timeouts (UplinkOnly/DownlinkOnly) on both ends.","Check for MTU/fragmentation issues if resets correlate with large uploads/downloads."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := task.Run(ctx, requestDone, responseDoneAndCloseWriter); err != nil {\n  if errors.Is(err, context.Canceled) || errors.Is(err, io.EOF) {\n    return nil // normal session end\n  }\n  return errors.New(\"connection ends\").Base(err)\n}","preventionTips":["Always unwrap the Base error before deciding severity.","Filter context.Canceled/io.EOF from logs to reduce noise.","Track per-outbound error rates to spot flaky servers."],"tags":["shadowsocks","network","tcp","relay","error-chain"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}