{"record":{"id":"e2b85c8b8df746f5","repo":"XTLS/Xray-core","slug":"failed-to-connect-to-server","errorCode":null,"errorMessage":"failed to connect to server","messagePattern":"failed to connect to server","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"proxy/shadowsocks_2022/outbound.go","lineNumber":83,"sourceCode":"\t}\n\n\toutbounds := session.OutboundsFromContext(ctx)\n\tob := outbounds[len(outbounds)-1]\n\tif !ob.Target.IsValid() {\n\t\treturn errors.New(\"target not specified\")\n\t}\n\tob.Name = \"shadowsocks-2022\"\n\tob.CanSpliceCopy = 3\n\tdestination := ob.Target\n\tnetwork := destination.Network\n\n\terrors.LogInfo(ctx, \"tunneling request to \", destination, \" via \", o.server.NetAddr())\n\n\tserverDestination := o.server\n\tserverDestination.Network = network\n\tconnection, err := dialer.Dial(ctx, serverDestination)\n\tif err != nil {\n\t\treturn errors.New(\"failed to connect to server\").Base(err)\n\t}\n\n\tif session.TimeoutOnlyFromContext(ctx) {\n\t\tctx, _ = context.WithCancel(context.Background())\n\t}\n\n\tif network == net.Network_TCP {\n\t\tserverConn := o.method.DialEarlyConn(connection, singbridge.ToSocksaddr(destination))\n\t\tvar handshake bool\n\t\tif timeoutReader, isTimeoutReader := link.Reader.(buf.TimeoutReader); isTimeoutReader {\n\t\t\tmb, err := timeoutReader.ReadMultiBufferTimeout(time.Millisecond * 100)\n\t\t\tif err != nil && err != buf.ErrNotTimeoutReader && err != buf.ErrReadTimeout {\n\t\t\t\treturn errors.New(\"read payload\").Base(err)\n\t\t\t}\n\t\t\tpayload := B.New()\n\t\t\tfor {\n\t\t\t\tpayload.Reset()\n\t\t\t\tnb, n := buf.SplitBytes(mb, payload.FreeBytes())","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/proxy/shadowsocks_2022/outbound.go#L65-L101","documentation":"Error \"failed to connect to server\" thrown in XTLS/Xray-core.","triggerScenarios":"Thrown at proxy/shadowsocks_2022/outbound.go:83 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"}