{"record":{"id":"fa512bd101a5b349","repo":"Tencent/WeKnora","slug":"failed-to-execute-request-w-fa512b","errorCode":null,"errorMessage":"failed to execute request: %w","messagePattern":"failed to execute request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/infrastructure/web_search/searxng.go","lineNumber":126,"sourceCode":"\t// Use \"all\" (SearXNG's documented value for \"no language filter\") instead\n\t// of \"auto\", which is a UI-side default and not a valid /search parameter.\n\t// safesearch is intentionally not set here so the value configured in the\n\t// instance's settings.yml is honored.\n\tq.Set(\"language\", \"all\")\n\n\treqURL := p.baseURL + \"/search?\" + q.Encode()\n\tlogger.Infof(ctx, \"[WebSearch][SearXNG] query=%q maxResults=%d url=%s\", query, maxResults, p.baseURL)\n\n\treq, err := http.NewRequestWithContext(ctx, http.MethodGet, reqURL, nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create request: %w\", err)\n\t}\n\treq.Header.Set(\"Accept\", \"application/json\")\n\treq.Header.Set(\"User-Agent\", \"WeKnora/1.0\")\n\n\tresp, err := p.client.Do(req)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to execute request: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode != http.StatusOK {\n\t\tbody, _ := io.ReadAll(io.LimitReader(resp.Body, 1024))\n\t\treturn nil, fmt.Errorf(\"searxng returned status %d: %s\", resp.StatusCode, string(body))\n\t}\n\n\tvar data searxngResponse\n\tif err := json.NewDecoder(resp.Body).Decode(&data); err != nil {\n\t\tp.lastUnresponsive = nil\n\t\treturn nil, fmt.Errorf(\"failed to decode SearXNG response (ensure JSON format is enabled in settings.yml): %w\", err)\n\t}\n\tp.lastUnresponsive = data.UnresponsiveEngines\n\n\tresults := make([]*types.WebSearchResult, 0, maxResults)\n\tfor _, r := range data.Results {\n\t\tif len(results) >= maxResults {","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/infrastructure/web_search/searxng.go#L108-L144","documentation":"The HTTP GET to the SearXNG instance failed at the transport layer: DNS failure, connection refused, TLS handshake error, or context cancellation/timeout. The provider wraps the underlying *url.Error so the root cause (e.g. 'connection refused') is preserved.","triggerScenarios":"SearXNG host unreachable or down; wrong port in baseURL; network egress blocked from the backend; ctx deadline exceeded while the request was in flight.","commonSituations":"SearXNG container not running or on a different Docker network; firewall/egress rules blocking outbound calls; DNS name typo; slow SearXNG instance exceeding the HTTP client timeout.","solutions":["Unwrap the error (errors.Unwrap or %v of the wrapped url.Error) to see the exact cause (refused vs timeout vs DNS)","Verify SearXNG is reachable: curl '<baseURL>/search?q=test&format=json' from the backend host","Fix baseURL host/port and any proxy configuration; confirm container networking (docker network) if self-hosted","Increase the HTTP client timeout or shorten the query workload if it is a timeout; add retry with backoff for transient network faults"],"exampleFix":"// before\nresults, err := provider.Search(ctx, q, 5, false)\nif err != nil { return err }\n// after\nresults, err := provider.Search(ctx, q, 5, false)\nif err != nil {\n    var netErr net.Error\n    if errors.As(err, &netErr) && netErr.Timeout() {\n        return retryWithBackoff(ctx, q) // transient timeout\n    }\n    return fmt.Errorf(\"web search unavailable: %w\", err)\n}","handlingStrategy":"retry","validationCode":"// preflight reachability check\nresp, err := http.Head(baseURL)\nif err != nil {\n    return fmt.Errorf(\"searxng unreachable: %w\", err)\n}\nresp.Body.Close()","typeGuard":null,"tryCatchPattern":"var netErr net.Error\nif errors.As(err, &netErr) && netErr.Timeout() {\n    // retry with backoff\n} else if strings.Contains(err.Error(), \"connection refused\") {\n    // service down: alert / fallback to another provider\n}","preventionTips":["Health-check the SearXNG endpoint at startup","Set sensible HTTP client timeouts and retry transient failures with backoff","Confirm container networking/egress rules before deploying","Monitor the provider and fail over to another web-search provider on repeated network errors"],"tags":["network","http","connection","searxng","timeout"],"backgroundTag":"connection-refused","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}