{"record":{"id":"f4a6ddd8c2c94f0e","repo":"XTLS/Xray-core","slug":"failed-to-dial-to-s","errorCode":null,"errorMessage":"failed to dial to %s","messagePattern":"failed to dial to (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"main/commands/all/api/shared.go","lineNumber":95,"sourceCode":"\tparsedTarget, err := url.Parse(target)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif s := strings.ToLower(parsedTarget.Scheme); s != \"http\" && s != \"https\" {\n\t\treturn nil, fmt.Errorf(\"invalid scheme: %s\", parsedTarget.Scheme)\n\t}\n\n\tclient := &http.Client{\n\t\tTimeout: 30 * time.Second,\n\t}\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, fmt.Errorf(\"failed to dial to %s\", target)\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode != 200 {\n\t\treturn nil, fmt.Errorf(\"unexpected HTTP status code: %d\", 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\")\n\t}\n\n\treturn content, nil\n}\n\nfunc showJSONResponse(m proto.Message) {\n\tif isNil(m) {\n\t\treturn","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/main/commands/all/api/shared.go#L77-L113","documentation":"fetchHTTPContent performs the GET with a 30s-timeout client and wraps transport failure as \"failed to dial to <target>\". Note the underlying error is discarded, so network vs DNS vs TLS problems are indistinguishable from the message alone. Only http/https targets reach this point.","triggerScenarios":"DNS resolution failure, connection refused/timeout, TLS handshake error, or firewall block while fetching remote content (geodata files, API endpoints) from the xray CLI.","commonSituations":"Blocked regions needing a proxy for outbound HTTPS; stale DNS; server down; egress firewall in containers; system clock skew breaking TLS certificate validation.","solutions":["Verify reachability independently: `curl -v <url>` from the same machine/user","Fix DNS (switch resolver) or route egress through a working proxy","If TLS/clock related, fix system time or CA store","Consider hosting the resource (e.g. geoip.dat) locally to avoid the remote fetch"],"exampleFix":"# diagnose (the error intentionally hides the cause)\ncurl -v https://example.com/geoip.dat\n# then fix DNS/proxy/egress accordingly","handlingStrategy":"retry","validationCode":"// pre-flight reachability check with the real cause preserved\nfunc reachable(target string, timeout time.Duration) error {\n    u, _ := url.Parse(target)\n    conn, err := net.DialTimeout(\"tcp\", u.Host, timeout)\n    if err != nil { return err }\n    return conn.Close()\n}","typeGuard":null,"tryCatchPattern":"var body []byte\nerr := backoffRetry(3, func() error {\n    var e error\n    body, e = fetchHTTPContent(target)\n    return e\n})\nif err != nil && strings.Contains(err.Error(), \"failed to dial\") {\n    // error hides the cause — re-diagnose out-of-band with curl before retrying further\n}","preventionTips":["The wrapper discards the net error — diagnose with curl -v when it fires","Mirror geodata locally to avoid runtime remote fetches","Ensure egress DNS/proxy work in the deployment environment"],"tags":["http","network","dns","tls"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}