{"record":{"id":"2a92be9573a39382","repo":"XTLS/Xray-core","slug":"connection-ends-2a92be","errorCode":null,"errorMessage":"connection ends","messagePattern":"connection ends","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"proxy/trojan/server.go","lineNumber":358,"sourceCode":"\t\t\treturn errors.New(\"failed to transfer request\").Base(err)\n\t\t}\n\t\treturn nil\n\t}\n\n\tresponseDone := func() error {\n\t\tdefer timer.SetTimeout(sessionPolicy.Timeouts.UplinkOnly)\n\n\t\tif err := buf.Copy(link.Reader, clientWriter, buf.UpdateActivity(timer)); err != nil {\n\t\t\treturn errors.New(\"failed to write response\").Base(err)\n\t\t}\n\t\treturn nil\n\t}\n\n\trequestDonePost := task.OnSuccess(requestDone, task.Close(link.Writer))\n\tif err := task.Run(ctx, requestDonePost, responseDone); err != nil {\n\t\tcommon.Must(common.Interrupt(link.Reader))\n\t\tcommon.Must(common.Interrupt(link.Writer))\n\t\treturn errors.New(\"connection ends\").Base(err)\n\t}\n\n\treturn nil\n}\n\nfunc (s *Server) fallback(ctx context.Context, err error, sessionPolicy policy.Session, connection stat.Connection, iConn stat.Connection, napfb map[string]map[string]map[string]*Fallback, first *buf.Buffer, firstLen int64, reader buf.Reader) error {\n\tif err := connection.SetReadDeadline(time.Time{}); err != nil {\n\t\terrors.LogWarningInner(ctx, err, \"unable to set back read deadline\")\n\t}\n\terrors.LogInfoInner(ctx, err, \"fallback starts\")\n\n\tname := \"\"\n\talpn := \"\"\n\tif tlsConn, ok := iConn.(*tls.Conn); ok {\n\t\tcs := tlsConn.ConnectionState()\n\t\tname = cs.ServerName\n\t\talpn = cs.NegotiatedProtocol\n\t\terrors.LogInfo(ctx, \"realName = \"+name)","sourceCodeStart":340,"sourceCodeEnd":376,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/proxy/trojan/server.go#L340-L376","documentation":"Aggregate error returned by the trojan TCP relay when task.Run finishes with a failure in either the request or response pipe (wraps [724] or [725] typically). Before returning it interrupts both link ends so no goroutine or buffer leaks. It marks the end of a trojan connection, not a protocol defect per se.","triggerScenarios":"Either requestDone or responseDone returned an error — i.e. any broken pipe during relaying — or the context was cancelled by the idle timer and a copy was treated as failure.","commonSituations":"Seen in bulk at server restart/shutdown (all connections torn down), during network churn, or after policy timeouts.","solutions":["Inspect the Base error chain to see which pipe failed and why","If it floods the log during shutdown, reduce log level for the trojan inbound","Fix the underlying copy failure per [724]/[725] guidance if it happens during active traffic"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := task.Run(ctx, requestDonePost, responseDone); err != nil {\n    common.Must(common.Interrupt(link.Reader))\n    common.Must(common.Interrupt(link.Writer))\n    return errors.New(\"connection ends\").Base(err)\n}","preventionTips":["Read the Base chain first; this error is only an aggregator for [724]/[725]","During planned shutdown expect a burst of these; lower loglevel before restarting","Never retry the whole connection automatically — clients own reconnection semantics"],"tags":["trojan","relay","lifecycle"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}