Skip to content

fix(segcache): prevent boot stream truncation via blocking catalog hydration with 30s timeout safety - #877

Merged
javi11 merged 2 commits into
javi11:mainfrom
drondeseries:fix/segcache-boot-truncation
Aug 31, 2026
Merged

fix(segcache): prevent boot stream truncation via blocking catalog hydration with 30s timeout safety#877
javi11 merged 2 commits into
javi11:mainfrom
drondeseries:fix/segcache-boot-truncation

Conversation

@drondeseries

Copy link
Copy Markdown
Contributor

Description

Fixes cold-start stream truncation by synchronizing segment cache access during startup catalog hydration.

Problem

Previously (#757), catalog loading was moved to a background goroutine and gated by an atomic.Bool loading flag. When a client requested a stream immediately after server boot:

  1. The cache map c.items was empty, so Get() returned misses for all cached segments.
  2. The reader was forced to cold-dial NNTP connections and fire 30–60 simultaneous requests over the wire.
  3. Put() silently skipped caching while loading was true, and any Put() that landed before the flag was set was clobbered when LoadCatalog() assigned c.items = valid.
  4. If any cold NNTP request stalled, http.ServeContent had already committed the 206 Partial Content header and Content-Length, resulting in an unexpected connection drop mid-stream (curl 18).

Solution

  • Replaced loading boolean with a ready chan struct{} and sync.Once.
  • Cache operations wait on c.waitReady() before accessing the map.
  • Added a 30 * time.Second bounded timeout (HydrationTimeout, configurable via Config) so degraded physical disk I/O or an uncalled LoadCatalog never indefinitely deadlocks streaming goroutines.
  • Added unit tests verifying blocking behavior and timeout fallback.

Verification

  • go test ./... passed across all packages.
  • golangci-lint passed with 0 issues.

@javi11
javi11 merged commit 0614008 into javi11:main Aug 31, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants