crowdsecurity/crowdsec · error

while performing request: %w

Error message

while performing request: %w

What it means

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.

Source

Thrown at pkg/apiclient/signal.go:26

	"github.com/crowdsecurity/crowdsec/pkg/modelscapi"
	log "github.com/sirupsen/logrus"
)

type SignalService service

func (s *SignalService) Add(ctx context.Context, signals *modelscapi.AddSignalsRequest) (interface{}, *Response, error) {
	u := fmt.Sprintf("%s/signals", s.client.URLPrefix)

	req, err := s.client.PrepareRequest(ctx, http.MethodPost, u, &signals)
	if err != nil {
		return nil, nil, fmt.Errorf("while building request: %w", err)
	}

	var response interface{}

	resp, err := s.client.Do(ctx, req, &response)
	if err != nil {
		return nil, resp, fmt.Errorf("while performing request: %w", err)
	}

	if resp.Response.StatusCode != http.StatusOK {
		log.Warnf("Signal push response : http %s", resp.Response.Status)
	} else {
		log.Debugf("Signal push response : http %s", resp.Response.Status)
	}

	return &response, resp, nil
}

View on GitHub (pinned to 909b515798)

Solutions

  1. Check basic connectivity to the API URL (curl the credentials.URL endpoint from the host)
  2. Verify config.Credentials.URL scheme/host in the crowdsec config (e.g. https://api.crowdsec.net)
  3. Inspect the wrapped error with errors.Is/As (net.Error, x509 errors, context.DeadlineExceeded) to pinpoint cause
  4. Retry with backoff for transient network errors; check proxy env vars if behind a proxy

Example fix

// before
resp, err := s.client.Do(ctx, req, &response)
if err != nil {
	return nil, resp, fmt.Errorf("while performing request: %w", err)
}
// after
resp, err := s.client.Do(ctx, req, &response)
if err != nil {
	if errors.Is(err, context.DeadlineExceeded) {
		return nil, resp, fmt.Errorf("signal push timed out: %w", err)
	}
	return nil, resp, fmt.Errorf("while performing request: %w", err)
}
Defensive patterns

Strategy: retry

Validate before calling

u, err := url.Parse(cfg.Credentials.URL)
if err != nil || u.Scheme == "" || u.Host == "" {
	return fmt.Errorf("invalid CAPI URL %q: %w", cfg.Credentials.URL, err)
}

Try / catch

resp, err := s.client.Do(ctx, req, &response)
if err != nil {
	var nerr net.Error
	switch {
	case errors.As(err, &nerr) && nerr.Timeout():
		// retry with backoff
	case errors.Is(err, context.Canceled):
		// abort, caller cancelled
	default:
		return nil, resp, fmt.Errorf("while performing request: %w", err)
	}
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06). Data as JSON: /api/errors/614c05900d9921f0. Report an issue: GitHub.