Skip to content

fix(proposals): add timeouts to source fetches and fix unstable_cache nesting - #2134

Open
sleyter93 wants to merge 4 commits into
mainfrom
fix/proposal-source-timeouts
Open

fix(proposals): add timeouts to source fetches and fix unstable_cache nesting#2134
sleyter93 wants to merge 4 commits into
mainfrom
fix/proposal-source-timeouts

Conversation

@sleyter93

Copy link
Copy Markdown
Collaborator

Summary

  • Wrap all getBlockNumber(config) calls with Promise.race + 10 s timeout (validate-source-sync.ts ×2, get-proposals-from-the-graph.ts ×1) — previously these wagmi RPC calls had no bound, and under a stalled RPC node they would hang indefinitely
  • Add AbortSignal.timeout(25_000) to every fetch() inside the Blockscout pagination loop — matches the timeout used in the canonical Blockscout fetch module (fetch-blockscout-get-logs-paginated.ts)
  • Add AbortSignal.timeout(10_000) to the Envio GraphQL fetch
  • Add logger.error when a source returns an empty array (previously silent) and when all sources are exhausted, making last-resort failures visible in logs
  • Fix triple-nested unstable_cache: fetchAllProposals now calls getProposalsFromBlockscoutUncached directly; transformProposalsIntoMap calls fetchAllProposals (raw) instead of getCachedProposals, so each cache wrapper only wraps raw functions
  • Update fetch-all-proposals.test.ts mock to target getProposalsFromBlockscoutUncached

Context

The process was being restarted by the container orchestrator after becoming unresponsive. Root cause: accumulated hung promises from timeout-less network calls during unstable_cache background revalidations (every 30 s). When the subgraph was stuck at block 7585149 (~16 k blocks behind), all three indexer-backed sources (Envio, DB, The Graph) failed, and Blockscout became the last resort — but its fetch() calls and the getBlockNumber() RPC calls had no timeout. Under a slow/stalled connection, these promises never settled, starving the event loop.

Reviewer notes

  • Individual source failures were already caught correctly — the fallback chain logic was not the issue
  • The process crash was operational (stuck subgraph + missing timeouts), not a logic bug
  • Timeout values: 10 s for RPC-like calls (matches FETCH_TIMEOUT_MS convention), 25 s for Blockscout pagination (matches REQUEST_TIMEOUT_MS in fetch-blockscout-get-logs-paginated.ts)

@github-actions

github-actions Bot commented Apr 29, 2026

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

… nesting

Without timeouts, hung RPC and HTTP calls (getBlockNumber, Blockscout
pagination, Envio GraphQL) accumulate in the event loop during background
revalidation, eventually starving the process and triggering a container
restart.

- Wrap getBlockNumber(config) with Promise.race + 10 s timeout in
  validate-source-sync.ts (both call sites) and get-proposals-from-the-graph.ts
- Add AbortSignal.timeout(25_000) to each fetch() in the Blockscout
  while-loop pagination, matching the timeout used in the canonical
  Blockscout fetch module
- Add AbortSignal.timeout(10_000) to the Envio GraphQL fetch
- Add logger.error when a source returns [] (previously silent) and when
  all sources are exhausted
- Fix triple-nested unstable_cache: fetchAllProposals now calls
  getProposalsFromBlockscoutUncached directly; transformProposalsIntoMap
  calls fetchAllProposals (raw) instead of getCachedProposals, so each
  cache wrapper only wraps raw functions

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sleyter93
sleyter93 force-pushed the fix/proposal-source-timeouts branch from 0b621da to b399849 Compare April 29, 2026 21:53
sleyter93 and others added 2 commits April 30, 2026 09:56
…outs

Adds structured timing logs to pinpoint 502 root cause during Blockscout
fallback conditions. Also fixes remaining timeout gaps identified in the
report.

Logging added:
- fetchAllProposals: concurrent revalidation counter (activeRevalidations),
  per-source elapsed time, total elapsed time
- fetchProposalLogsFromBlockscout: page count + total elapsed on completion
  and on error
- fetchVaultLogsAllPagesForTopic: per-topic page count + elapsed
- fetchVaultLogsForTopics: total topics, merged item count, total elapsed
- fetchClaimedItemsFromTheGraph: per-page timing + total, hard cap at 100
  pages (was unbounded)
- _lastBlockNumber (health check): db block, chain block, healthy flag,
  elapsed

Timeouts added:
- getBlockNumber in health check: 5 s Promise.race (was unbounded; ECS
  health check failures cause rolling restarts → 502 during replacement)
- envio-sync-check all 4 fetch calls: AbortSignal.timeout(10_000)
- discourse/topic fetch: AbortSignal.timeout(10_000)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When all proposal sources fail or return empty, fetchAllProposals now
throws instead of returning an empty array. This prevents unstable_cache
from overwriting a previously good cache entry with an empty result,
which was causing users to see 0 proposals for up to 30s after a
Blockscout timeout. The route now catches the throw and returns 503.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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