Documentation
¶
Overview ¶
Package blocklistfeed is the remote blocklist syncer: it periodically downloads one or more remote blocklists (one domain per line, '#' comments allowed) and merges new entries into the live blocklist without removing manually-added entries. Extracted from package main per ADR-0002; it depends on the Blocklist hub only through the narrow Merger interface (main passes its *Blocklist) and on the internal/ssrf seam for the outbound fetch guard. package main keeps the blFeedSyncer singleton and the admin API handler (blocklist_feed.go shim).
Multi-feed: each feed has its own URL, sync interval, and status. A single scheduler goroutine (Start) wakes every tickInterval and syncs every feed that is due. The scheduler is ALWAYS started at startup — feeds added later via the admin API are picked up on the next tick without a restart.
CHAOS-108: the fourth feed loop ¶
internal/feedsched exists to fix two named failure modes in Culvert's periodic feeds — "a failed round is not retried until the next full interval" and "a fleet stays in phase forever" — and its package doc enumerates THREE feed loops. This was the fourth, and it had both defects plus the sharper version of the first:
- A failed sync stamped the attempt time and the due-check gated on it, so ANY transient failure (DNS blip, a 503 from the origin, a connection reset, a TLS error) pushed the next attempt a FULL interval away — DefaultInterval, 24 hours, on a stock install. Nothing retried in between. The worst shape is the boot pass: the immediate round runs because no attempt has been recorded, so a node that boots into a feed outage merges NO domains from that feed — not stale entries, none — and does not try again for a day. The blocklist is a deny control, so that window is fail-open on exactly the destinations the operator configured the feed to block.
- The cadence carried no jitter and its phase was pinned at boot, so nodes that boot together (rolling upgrade, compose restart, a hypervisor recovering a rack) sync together against a third-party origin forever. That closes the same loop feedsched's doc describes: the herd provokes the rate-limit, and the absent retry then holds the whole fleet at that failure for the full interval.
- The fetch was parented to context.Background(), so shutdown could not interrupt an in-flight sync.
The fix reuses the OWNER's ladder rather than growing a second one: each feed holds a feedsched.Scheduler used purely as a delay calculator (NextDelay), which brings bounded exponential backoff, the interval-aware floor/ceiling clamp that keeps retrying a strict TIGHTENING of the cadence, and a stable per-feed jitter offset. The single shared tick is kept, so a feed added through the admin API is still picked up within one tick and no goroutine is created per feed.
NOT fixed here, and recorded as the open half: this feed still has no staleness alert or health row. internal/threatfeed has both (a threat_feed_stale alert, plus a deferred startup variant); a blocklist feed that has never synced, or is arbitrarily stale, raises neither and is visible only as LastError in the admin API and one log line per attempt. Adding an alert type is an owner decision with GUI/API parity consequences, not a drive-by rider on a scheduling fix.
Index ¶
- Constants
- type Feed
- type Merger
- type Syncer
- func (bs *Syncer) ClearFeeds()
- func (bs *Syncer) Feeds() []Feed
- func (bs *Syncer) RemoveFeed(feedURL string) bool
- func (bs *Syncer) SetFeed(feedURL string, interval time.Duration)
- func (bs *Syncer) Start(ctx context.Context)
- func (bs *Syncer) SyncAll() (int, error)
- func (bs *Syncer) SyncFeed(feedURL string) (int, error)
- func (bs *Syncer) SyncFeedContext(ctx context.Context, feedURL string) (int, error)
Constants ¶
const ( // DefaultInterval is the fallback auto-sync interval when none is // configured. Exported for the main-side callers (admin settings restore, // startup config, API handler) that pick the interval. DefaultInterval = 24 * time.Hour )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Feed ¶
type Feed struct {
URL string
Interval time.Duration // 0 = auto-sync disabled (manual Sync Now only)
LastSync time.Time // last successful sync (zero = never)
LastError string // error from the most recent attempt ("" = ok)
ImportedCount int64 // cumulative new domains merged from this feed
}
Feed is a point-in-time status snapshot of one configured feed, returned by Feeds() for the admin API and settings persistence.
type Merger ¶
Merger is the blocklist surface the syncer needs: fold downloaded feed lines into the live blocklist and report how many were newly added. main's *Blocklist satisfies this (MergeFromLines).
type Syncer ¶
type Syncer struct {
// contains filtered or unexported fields
}
Syncer downloads and merges remote domain feeds into a Merger. The zero value is safe for all methods (feeds map is lazily initialized).
func New ¶
New creates an empty syncer for bl. Feeds are added via SetFeed (startup config seed or admin API).
func (*Syncer) ClearFeeds ¶
func (bs *Syncer) ClearFeeds()
ClearFeeds removes every configured feed. Used when restoring persisted settings, which are authoritative over the YAML/CLI startup seed. Domains already merged into the blocklist are NOT removed.
func (*Syncer) Feeds ¶
Feeds returns a snapshot of all configured feeds, sorted by URL for deterministic API output and persistence. A nil syncer (feeds never configured/initialized) has no feeds — return empty rather than panic, so the read-only /api/blocklist/feed endpoint stays a 200 in that state. (Upstream fix ae1b1c1, ported into the extracted engine at merge time.)
func (*Syncer) RemoveFeed ¶
RemoveFeed deletes a feed by URL. Returns false when no such feed exists. Domains already merged into the blocklist are NOT removed (feed imports are merge-only by design).
func (*Syncer) SetFeed ¶
SetFeed adds or updates a feed. interval 0 disables auto-sync for that feed (it can still be synced manually). Existing sync statistics are preserved on update.
func (*Syncer) Start ¶
Start launches the background scheduler. It runs an immediate pass, then wakes every tickInterval and syncs each feed whose interval has elapsed since its last attempt. Feeds with interval 0 are skipped.
func (*Syncer) SyncAll ¶
SyncAll syncs every configured feed (manual "Refresh All Now"), regardless of interval. Returns the total domains added and the first error encountered.
func (*Syncer) SyncFeed ¶
SyncFeed fetches one feed by URL and merges new domains into the blocklist. Returns the number of new domains added and any error encountered. The feed's status fields are updated either way.
Deliberately NOT parented to the caller's request context: this is the manual "Sync Now" path, and an operator who clicks it and then navigates away must not abort the fetch. The SCHEDULER path uses SyncFeedContext so shutdown can interrupt it.
func (*Syncer) SyncFeedContext ¶ added in v1.0.385
SyncFeedContext is SyncFeed with a caller-supplied context, used by the scheduler so a shutdown interrupts an in-flight fetch rather than waiting out httpTimeout (CHAOS-108).