crowdsecurity/crowdsec · error

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

Error message

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

What it means

Wraps the error from dbClient.GetConfigItem for the per-blocklist `blocklist:<name>:last_pull` config item. Only force-pulled blocklists skip this lookup. It records when the blocklist was last fetched; a failed read can indicate a DB problem or a config-item storage issue.

Source

Thrown at pkg/apiserver/apic.go:967

		_forcePull, err := a.ShouldForcePullBlocklist(ctx, blocklist)
		if err != nil {
			return fmt.Errorf("while checking if we should force pull blocklist %s: %w", *blocklist.Name, err)
		}

		forcePull = _forcePull
	}

	blocklistConfigItemName := fmt.Sprintf("blocklist:%s:last_pull", *blocklist.Name)

	var (
		lastPullTimestamp string
		err               error
	)

	if !forcePull {
		lastPullTimestamp, err = a.dbClient.GetConfigItem(ctx, blocklistConfigItemName)
		if err != nil {
			return fmt.Errorf("while getting last pull timestamp for blocklist %s: %w", *blocklist.Name, err)
		}
	}

	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
	}

View on GitHub (pinned to 909b515798)

Solutions

  1. Check DB connectivity and health (`cscli db doctor`).
  2. If the item is genuinely missing this is not an error — NotFound is returned as empty string by the caller, so inspect the wrapped error for the real cause.
  3. Enable SQLite WAL mode.
  4. Re-run the pull once the database is healthy; the timestamp will be re-read next cycle.
Defensive patterns

Strategy: try-catch

Validate before calling

// check DB health before pull: cscli db doctor

Try / catch

lastPullTimestamp, err = a.dbClient.GetConfigItem(ctx, name)
if err != nil {
    if ent.IsNotFound(err) { lastPullTimestamp = "" } else { return err }
}

Prevention

When it happens

Trigger: updateBlocklist without forcePull queries the config item and the DB read fails (DB down, context cancelled, ent query error).

Common situations: SQLite/PostgreSQL unavailable mid-cycle, DB corruption of config_items table, interrupted migration leaving the table inaccessible.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


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