crowdsecurity/crowdsec · error

while setting last pull timestamp for blocklist %s: %w

Error message

while setting last pull timestamp for blocklist %s: %w

What it means

Wraps the error from dbClient.SetConfigItem when storing the new `blocklist:<name>:last_pull` timestamp after a successful pull. The inner error is a database write failure (DB unavailable, constraint error, context cancelled).

Source

Thrown at pkg/apiserver/apic.go:988

	decisions, hasChanged, err := client.Decisions.GetDecisionsFromBlocklist(ctx, blocklist, lastPullTimestamp)
	if err != nil {
		return fmt.Errorf("while getting decisions from blocklist %s: %w", *blocklist.Name, err)
	}

	if !hasChanged {
		if lastPullTimestamp == "" {
			log.Infof("blocklist %s hasn't been modified or there was an error reading it, skipping", *blocklist.Name)
		} else {
			log.Infof("blocklist %s hasn't been modified since %s, skipping", *blocklist.Name, lastPullTimestamp)
		}

		return nil
	}

	err = a.dbClient.SetConfigItem(ctx, blocklistConfigItemName, time.Now().UTC().Format(http.TimeFormat))
	if err != nil {
		return fmt.Errorf("while setting last pull timestamp for blocklist %s: %w", *blocklist.Name, err)
	}

	if len(decisions) == 0 {
		log.Infof("blocklist %s has no decisions", *blocklist.Name)
		return nil
	}
	// apply APIC specific whitelists
	decisions = a.ApplyApicWhitelists(ctx, decisions)
	alert := createAlertForDecision(decisions[0], types.CAPIAlertKind)
	alertsFromCapi := []*models.Alert{alert}
	alertsFromCapi = fillAlertsWithDecisions(alertsFromCapi, decisions, addCounters)

	err = a.SaveAlerts(ctx, alertsFromCapi, addCounters, nil)
	if err != nil {
		return fmt.Errorf("while saving alert from blocklist %s: %w", *blocklist.Name, err)
	}

	return nil

View on GitHub (pinned to 909b515798)

Solutions

  1. Check disk space and filesystem permissions on the DB file.
  2. Verify DB health (`cscli db doctor`) and connectivity.
  3. Enable SQLite WAL mode.
  4. Re-run the pull; the next cycle will rewrite the timestamp (worst case the blocklist is re-pulled fully).
Defensive patterns

Strategy: try-catch

Validate before calling

// check disk space and DB writability before pulls
cscli db doctor

Try / catch

if err := a.dbClient.SetConfigItem(ctx, name, ts); err != nil {
    log.Warnf("could not persist last_pull timestamp: %v", err)
    // worst case: blocklist is re-pulled next cycle
}

Prevention

When it happens

Trigger: updateBlocklist finished pulling decisions and writes the current UTC time as config item; the DB write fails, e.g. SQLite read-only filesystem, disk full, connection lost.

Common situations: Disk full or read-only mount on the SQLite file, PostgreSQL dropped connection, concurrent write lock timeouts.

Related errors


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