{"record":{"id":"11fd2f9a0f44ba8f","repo":"XTLS/Xray-core","slug":"failed-to-dial-to","errorCode":null,"errorMessage":"failed to dial to ","messagePattern":"failed to dial to ","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"main/confloader/external/external.go","lineNumber":82,"sourceCode":"\t}\n\n\tif socketPath != \"\" {\n\t\tdialAddr := utils.ResolveSocketPath(socketPath)\n\t\tclient.Transport = &http.Transport{\n\t\t\tDialContext: func(ctx context.Context, _, _ string) (net.Conn, error) {\n\t\t\t\tvar d net.Dialer\n\t\t\t\treturn d.DialContext(ctx, \"unix\", dialAddr)\n\t\t\t},\n\t\t}\n\t}\n\n\tresp, err := client.Do(&http.Request{\n\t\tMethod: \"GET\",\n\t\tURL:    parsedTarget,\n\t\tClose:  true,\n\t})\n\tif err != nil {\n\t\treturn nil, errors.New(\"failed to dial to \", target).Base(err)\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode != 200 {\n\t\treturn nil, errors.New(\"unexpected HTTP status code: \", resp.StatusCode)\n\t}\n\n\tcontent, err := buf.ReadAllToBytes(resp.Body)\n\tif err != nil {\n\t\treturn nil, errors.New(\"failed to read HTTP response\").Base(err)\n\t}\n\n\treturn content, nil\n}\n\n// isRemoteSource reports whether arg should be fetched via HTTP (regular\n// network or Unix socket) rather than read from the local filesystem.\n// Recognized forms:","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/main/confloader/external/external.go#L64-L100","documentation":"Returned when http.Client.Do fails while fetching remote config content in FetchHTTPContent. This covers every transport-level failure: DNS resolution errors, refused/timeout connections, TLS handshake failures, and unreachable Unix/abstract sockets (the transport dials 'unix' when socketPath is non-empty). The original error is attached via Base(err), so the cause is preserved.","triggerScenarios":"client.Do(&http.Request{Method:\"GET\", URL:parsedTarget, Close:true}) failing: host down or unresolvable, 30s timeout exceeded, TLS certificate mismatch on https, or a socket target whose socket file does not exist / is not listening (abstract socket name wrong on Linux/Android).","commonSituations":"Fetch happens at startup so misconfigurations surface as boot failure; typical cases are pointing -config at a dead URL, a proxy-side Unix socket (e.g. a local API daemon) not started yet, DNS failure in a sandboxed environment, or self-signed certs when fetching over https.","solutions":["Read the wrapped error (it is chained with .Base(err)) to see whether it is DNS, timeout, TLS, or unix-dial specific","For socket targets, verify the socket exists and is listening: ls -l /path/to/socket.sock or ss -x | grep <name>; start the serving process first","For https targets, verify the certificate is trusted or fetch over http within a trusted network","Verify network/DNS availability from the machine (curl the same URL) and increase reachability before retrying"],"exampleFix":"# before\nxray run -config http://10.0.0.5:8080/config.json   # server down -> failed to dial to ...\n\n# after\n# confirm the endpoint answers, then run\ncurl -f http://10.0.0.5:8080/config.json && xray run -config http://10.0.0.5:8080/config.json","handlingStrategy":"retry","validationCode":"// for socket targets\nif _, err := os.Stat(sockPath); err != nil {\n    return fmt.Errorf(\"socket %s not ready: %w\", sockPath, err)\n}\n// for https targets\nif conn, err := net.DialTimeout(\"tcp\", hostPort, 3*time.Second); err == nil { conn.Close() }","typeGuard":null,"tryCatchPattern":"var netErr net.Error\nif errors.As(err, &netErr) && netErr.Timeout() { backoff.Retry(fetch, 3) }","preventionTips":["Health-check remote config endpoints before boot (curl -f)","Start socket-serving processes before Xray in service unit ordering (After=/Requires=)","Cache the last good config locally so boot survives a temporarily unreachable endpoint"],"tags":["go","xray","network","http","unix-socket","config"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}