{"record":{"id":"614c05900d9921f0","repo":"crowdsecurity/crowdsec","slug":"while-performing-request-w-614c05","errorCode":null,"errorMessage":"while performing request: %w","messagePattern":"while performing request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/apiclient/signal.go","lineNumber":26,"sourceCode":"\t\"github.com/crowdsecurity/crowdsec/pkg/modelscapi\"\n\tlog \"github.com/sirupsen/logrus\"\n)\n\ntype SignalService service\n\nfunc (s *SignalService) Add(ctx context.Context, signals *modelscapi.AddSignalsRequest) (interface{}, *Response, error) {\n\tu := fmt.Sprintf(\"%s/signals\", s.client.URLPrefix)\n\n\treq, err := s.client.PrepareRequest(ctx, http.MethodPost, u, &signals)\n\tif err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"while building request: %w\", err)\n\t}\n\n\tvar response interface{}\n\n\tresp, err := s.client.Do(ctx, req, &response)\n\tif err != nil {\n\t\treturn nil, resp, fmt.Errorf(\"while performing request: %w\", err)\n\t}\n\n\tif resp.Response.StatusCode != http.StatusOK {\n\t\tlog.Warnf(\"Signal push response : http %s\", resp.Response.Status)\n\t} else {\n\t\tlog.Debugf(\"Signal push response : http %s\", resp.Response.Status)\n\t}\n\n\treturn &response, resp, nil\n}\n","sourceCodeStart":8,"sourceCodeEnd":37,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/apiclient/signal.go#L8-L37","documentation":"Add() pushes a signal (alert) to the CrowdSec CAPI/LAPI and wraps any transport-level failure from client.Do with this message. It means the HTTP request itself could not be completed (connection failure, TLS error, timeout, malformed request) before a status could even be evaluated. The original error is preserved via %w for errors.Is/As inspection.","triggerScenarios":"s.client.Do(ctx, req, &response) returns a non-nil error while pushing a signal — e.g. the CAPI/LAPI URL is unreachable, DNS fails, TLS handshake fails, the request context is cancelled, or the serialized request is rejected at transport level.","commonSituations":"Firewall/proxy blocking api.crowdsec.net; invalid credentials URL with wrong scheme; network outage on the machine pushing alerts; VPN or DNS misconfiguration; CAPI service temporarily down; ctx deadline exceeded under slow links.","solutions":["Check basic connectivity to the API URL (curl the credentials.URL endpoint from the host)","Verify config.Credentials.URL scheme/host in the crowdsec config (e.g. https://api.crowdsec.net)","Inspect the wrapped error with errors.Is/As (net.Error, x509 errors, context.DeadlineExceeded) to pinpoint cause","Retry with backoff for transient network errors; check proxy env vars if behind a proxy"],"exampleFix":"// before\nresp, err := s.client.Do(ctx, req, &response)\nif err != nil {\n\treturn nil, resp, fmt.Errorf(\"while performing request: %w\", err)\n}\n// after\nresp, err := s.client.Do(ctx, req, &response)\nif err != nil {\n\tif errors.Is(err, context.DeadlineExceeded) {\n\t\treturn nil, resp, fmt.Errorf(\"signal push timed out: %w\", err)\n\t}\n\treturn nil, resp, fmt.Errorf(\"while performing request: %w\", err)\n}","handlingStrategy":"retry","validationCode":"u, err := url.Parse(cfg.Credentials.URL)\nif err != nil || u.Scheme == \"\" || u.Host == \"\" {\n\treturn fmt.Errorf(\"invalid CAPI URL %q: %w\", cfg.Credentials.URL, err)\n}","typeGuard":null,"tryCatchPattern":"resp, err := s.client.Do(ctx, req, &response)\nif err != nil {\n\tvar nerr net.Error\n\tswitch {\n\tcase errors.As(err, &nerr) && nerr.Timeout():\n\t\t// retry with backoff\n\tcase errors.Is(err, context.Canceled):\n\t\t// abort, caller cancelled\n\tdefault:\n\t\treturn nil, resp, fmt.Errorf(\"while performing request: %w\", err)\n\t}\n}","preventionTips":["Validate credentials.URL parses and has scheme+host before constructing the client","Add timeout to contexts so pushes fail fast instead of hanging","Monitor network/DNS health on hosts pushing signals; set proxy env vars explicitly if needed"],"tags":["network","http","api-client","crowdsec"],"backgroundTag":"http-request-failed","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}