Skip to content

Testing - #125

Merged
bietiekay merged 7 commits into
masterfrom
testing
Mar 6, 2026
Merged

Testing#125
bietiekay merged 7 commits into
masterfrom
testing

Conversation

@bietiekay

Copy link
Copy Markdown
Owner

No description provided.

Daniel Kirstenpfad added 7 commits January 16, 2026 20:11
The /api/statistics endpoint was returning {pending: true} indefinitely
when the statistics snapshot build got stuck. This could happen due to:
- Worker thread deadlocks or promises that never resolve
- Slow or hanging getCacheCoverage() calls with large caches
- Redis operations that never complete
- Stale snapshots in Redis not triggering refresh

Changes:
- Add 10-minute timeout to snapshot builds to prevent infinite hangs
- Detect and automatically reset stuck builds in SnapshotCache
- Wrap getCacheCoverage() in try-catch to prevent blocking failures
- Detect stale snapshots (>2x refresh interval) and force refresh
- Add comprehensive logging for build duration and stuck detection
- Clear dirty flag on timeout/error to allow retry

The timeout mechanism ensures that even if a build hangs, it will
eventually timeout and allow the next refresh attempt to proceed.
Error handling ensures snapshot builds complete even if cache coverage
fails, returning partial statistics instead of hanging.

Fixes issue where statistics endpoint hung for 12+ hours while server
remained responsive (indicating deadlock/promise issue, not CPU bound).
TypeScript couldn't narrow the type of refreshStartTime in the compound
condition. Store it in a local variable to allow proper type narrowing.
# Conflicts:
#	.specstory/history/2026-01-17_11-32Z-statistics-endpoint-hanging.md
#	src/stats.ts
@bietiekay
bietiekay merged commit 06b6442 into master Mar 6, 2026
@bietiekay
bietiekay deleted the testing branch March 6, 2026 18:09
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.

1 participant