π‘οΈ Sentinel: [MEDIUM] Add timeouts to external API calls - #34
π‘οΈ Sentinel: [MEDIUM] Add timeouts to external API calls#34felirami wants to merge 1 commit into
Conversation
Co-authored-by: felirami <6752178+felirami@users.noreply.github.com>
|
π Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a π emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
CodeAnt AI is reviewing your PR. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Thanks for using CodeAnt! πWe're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X Β· |
| ...(githubToken ? { Authorization: `Bearer ${githubToken}` } : {}), | ||
| }, | ||
| signal: AbortSignal.timeout(30_000), | ||
| }); |
There was a problem hiding this comment.
π‘ Medium scripts/sync-sources.mjs:36
fetchGithubJson() aborts every request after 30s via AbortSignal.timeout, but timeouts throw a TimeoutError/AbortError rather than returning a non-OK HTTP status. When getRepoTree() and getLatestRelease() call it with { optional: true }, a slow GitHub API response throws and propagates up through buildRepoSnapshot() to main(), which calls process.exit(1) β so one slow response fails the entire snapshot generation instead of skipping that optional source and leaving src/data/farcasterorg-sources.json stale. Consider catching AbortError/timeout exceptions in fetchGithubJson() and returning null when optional is true, or catching timeouts at the optional call sites.
π Reply "fix it for me" or copy this AI Prompt for your agent:
In file @scripts/sync-sources.mjs around line 36:
`fetchGithubJson()` aborts every request after 30s via `AbortSignal.timeout`, but timeouts throw a `TimeoutError`/`AbortError` rather than returning a non-OK HTTP status. When `getRepoTree()` and `getLatestRelease()` call it with `{ optional: true }`, a slow GitHub API response throws and propagates up through `buildRepoSnapshot()` to `main()`, which calls `process.exit(1)` β so one slow response fails the entire snapshot generation instead of skipping that optional source and leaving `src/data/farcasterorg-sources.json` stale. Consider catching `AbortError`/timeout exceptions in `fetchGithubJson()` and returning `null` when `optional` is true, or catching timeouts at the optional call sites.
| "X-GitHub-Api-Version": "2022-11-28", | ||
| ...(githubToken ? { Authorization: `Bearer ${githubToken}` } : {}), | ||
| }, | ||
| signal: AbortSignal.timeout(30_000), |
There was a problem hiding this comment.
Suggestion: Adding a hard timeout here introduces a new rejection path that bypasses the optional fallback logic, so optional GitHub reads can now fail the entire sync job instead of degrading gracefully. Handle timeout/abort errors in fetchGithubJson and return null when optional is true. [incomplete implementation]
Severity Level: Major β οΈ
- β Daily sync script fails on optional JSON timeouts.
- β οΈ Snapshot src/data/farcasterorg-sources.json stops updating.
- β οΈ Frontend data via src/lib/sources.ts becomes stale.Steps of Reproduction β
1. Run the source sync script via `npm run sync:sources` defined in `package.json:11`,
which executes `node scripts/sync-sources.mjs`.
2. Execution enters `main()` in `scripts/sync-sources.mjs:246-254`, which iterates
`sortedRepos` and calls `buildRepoSnapshot(repo)` at line 253 for each repository.
3. Inside `buildRepoSnapshot()` (`scripts/sync-sources.mjs:176-244`), `getRepoTree()` at
lines 146-157 and `getLatestRelease()` at lines 159-173 are called; both invoke
`fetchGithubJson(..., { optional: true })` to GitHub JSON endpoints.
4. `fetchGithubJson()` (`scripts/sync-sources.mjs:28-48`) calls `fetch()` with `signal:
AbortSignal.timeout(30_000)` at line 35; when GitHub or the network hangs >30s, `fetch()`
rejects with `AbortError`, so the 404/409 + `optional` fallback at lines 38-40 never runs,
the rejection bubbles to `main()`, and the top-level `main().catch` at lines 48-51 logs
the error and exits with status 1, aborting the entire sync job instead of returning
`null` for optional data.(Use Cmd/Ctrl + Click for best experience)
Prompt for AI Agent π€
This is a comment left during a code review.
**Path:** scripts/sync-sources.mjs
**Line:** 35:35
**Comment:**
*Incomplete Implementation: Adding a hard timeout here introduces a new rejection path that bypasses the `optional` fallback logic, so optional GitHub reads can now fail the entire sync job instead of degrading gracefully. Handle timeout/abort errors in `fetchGithubJson` and return `null` when `optional` is true.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix| "X-GitHub-Api-Version": "2022-11-28", | ||
| ...(githubToken ? { Authorization: `Bearer ${githubToken}` } : {}), | ||
| }, | ||
| signal: AbortSignal.timeout(30_000), |
There was a problem hiding this comment.
Suggestion: This timeout adds the same unhandled abort path to text fetches, which means optional markdown/doc fetches can now throw and terminate the script before fallback behavior runs. Catch timeout/abort errors in fetchGithubText and return an empty string when optional is true. [incomplete implementation]
Severity Level: Major β οΈ
- β Sync script crashes on optional GitHub text timeouts.
- β οΈ Docs metadata and summaries fail to refresh.
- β οΈ UI relying on sources snapshot shows outdated documentation.Steps of Reproduction β
1. Run the source sync via `npm run sync:sources` (`package.json:11`), which executes
`scripts/sync-sources.mjs` to generate `src/data/farcasterorg-sources.json` (described in
`README.md:27-29`).
2. `main()` (`scripts/sync-sources.mjs:246-254`) calls `buildRepoSnapshot(repo)` at line
253; inside `buildRepoSnapshot()` (`176-244`), multiple optional markdown/doc calls use
`fetchGithubText(..., { optional: true })` at lines 178-180 (README), 189-193 (hyper.md),
and 199-211 (SUMMARY.md, introduction.md, getting-started.md). `enrichDocsLinks()` at
lines 53-87 also calls `fetchGithubText(..., { optional: true })` at lines 58-61.
3. `fetchGithubText()` (`scripts/sync-sources.mjs:50-69`) invokes `fetch()` with `signal:
AbortSignal.timeout(30_000)` at line 57 and only treats 404/409 responses as optional
fallbacks, returning `""` when `optional` is true at lines 60-62.
4. When any of these GitHub text endpoints or the network stalls for more than 30 seconds,
`fetch()` rejects with `AbortError`, so the 404/409 + `optional` fallback at lines 60-62
is skipped, the rejection propagates through `buildRepoSnapshot()` / `enrichDocsLinks()`
back to `main()`, and `main().catch` at lines 48-51 logs the error and exits with status
1, causing optional markdown/doc fetches to fail hard and terminate the script.(Use Cmd/Ctrl + Click for best experience)
Prompt for AI Agent π€
This is a comment left during a code review.
**Path:** scripts/sync-sources.mjs
**Line:** 57:57
**Comment:**
*Incomplete Implementation: This timeout adds the same unhandled abort path to text fetches, which means optional markdown/doc fetches can now throw and terminate the script before fallback behavior runs. Catch timeout/abort errors in `fetchGithubText` and return an empty string when `optional` is true.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix|
CodeAnt AI finished reviewing your PR. |
User description
π¨ Severity: MEDIUM
π‘ Vulnerability: Missing timeouts on external
fetchcalls. Node's nativefetchdoes not have a default timeout, meaning unresponsive external servers can cause connections to hang indefinitely.π― Impact: Hanging requests can lead to thread/resource exhaustion and degrade the application's responsiveness, introducing a risk of Denial of Service (DoS).
π§ Fix: Added explicit timeouts using
signal: AbortSignal.timeout(TIMEOUT_MS)tofetchcalls insrc/lib/network.ts,src/lib/snap-market.ts, andscripts/sync-sources.mjs.β Verification: Ran
npm run lint,npm run typecheck, andnpm run build.PR created automatically by Jules for task 5752759091545973092 started by @felirami
Note
Low Risk
Bounded timeouts on read-only external calls improve resilience; slow-but-valid responses may now fail with timeout errors instead of eventually succeeding.
Overview
Hardens outbound HTTP so native
fetchcalls cannot hang forever when GitHub, the public node, or Dexscreener stops responding.scripts/sync-sources.mjsnow passessignal: AbortSignal.timeout(30_000)on both GitHub JSON and raw-text helpers.getNetworkStatusinsrc/lib/network.tsuses the existingNODE_PROBE_TIMEOUT_MS(10s) the same way.getSnapMarketDatainsrc/lib/snap-market.tsintroducesMARKET_FETCH_TIMEOUT_MS(10s) for the Dexscreener request.A Sentinel entry in
.jules/sentinel.mddocuments the gap and theAbortSignal.timeoutprevention pattern.Reviewed by Cursor Bugbot for commit 22bfe37. Bugbot is set up for automated code reviews on this repo. Configure here.
CodeAnt-AI Description
Add timeouts to external fetch requests
What Changed
Impact
β Fewer hanging requestsβ Lower risk of stalled background jobsβ More reliable external API checksπ‘ Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.
Note
Add
AbortSignal.timeoutto external API calls in sync scripts and network probesfetchGithubJsonandfetchGithubTextin sync-sources.mjs viaAbortSignal.timeout(30_000).getNetworkStatusin network.ts usingNODE_PROBE_TIMEOUT_MS.getSnapMarketDatain snap-market.ts via a newMARKET_FETCH_TIMEOUT_MSconstant.AbortError(or returnok:false) instead of hanging indefinitely.π Macroscope summarized 22bfe37. 4 files reviewed, 0 issues evaluated, 0 issues filtered, 0 comments posted
ποΈ Filtered Issues
No issues evaluated.