Skip to content

fix(dsn): prevent hang during DSN auto-detection in repos with test fixtures#445

Merged
BYK merged 3 commits intomainfrom
fix/dsn-discovery-hang
Mar 17, 2026
Merged

fix(dsn): prevent hang during DSN auto-detection in repos with test fixtures#445
BYK merged 3 commits intomainfrom
fix/dsn-discovery-hang

Conversation

@BYK
Copy link
Copy Markdown
Member

@BYK BYK commented Mar 17, 2026

Running sentry issues without explicit flags in repos containing test fixture DSNs (e.g., the CLI repo itself) caused the process to hang. PR #420 bumped scan depth from 2→3, causing test/ directories to be scanned — finding ~86 fake DSNs that were all resolved via unbounded Promise.all, triggering 190+ concurrent API requests, rate limiting (429), and retry storms.

Changes

  • Skip test directories in scanner — Add test/, tests/, __mocks__/, fixtures/, __fixtures__/ to ALWAYS_SKIP_DIRS. Test directories contain fixture DSNs, not real Sentry configuration.
  • Deduplicate DSNs before resolution — Group by (orgId, projectId) or publicKey, resolving only one representative per unique pair. Reduces ~86 DSNs to ~10-20 unique API calls.
  • Add concurrency limitp-limit(5) on DSN resolution API calls to prevent overwhelming the Sentry API.
  • Add 15s timeout — Race Promise.all against a deadline, returning partial results on timeout so the CLI never hangs indefinitely.
  • In-flight dedup for resolveOrgRegion — Concurrent calls for the same orgSlug share a single HTTP request via a module-level promise cache.
  • Fix getDirMtime dynamic import — Replace wasteful await import("node:fs/promises") (called 75+ times) with a static import.

Relates to #420 and #414.

…ixtures

DSN auto-detection was hanging when run in repos containing many test
fixture DSNs (e.g., the CLI repo itself). PR #420 bumped scan depth
from 2→3, causing test/ directories to be scanned. This found ~86 fake
DSNs that were all resolved via unbounded Promise.all — triggering 190+
concurrent API requests, rate limiting, and retry storms.

Fixes:
- Skip test/, tests/, __mocks__, fixtures/, __fixtures__ in scanner
- Deduplicate DSNs by (orgId, projectId) before API resolution
- Add p-limit(5) concurrency cap on DSN resolution API calls
- Add 15s timeout with partial results for DSN resolution
- Add in-flight promise dedup for resolveOrgRegion (concurrent calls
  for the same org share one HTTP request)
- Fix getDirMtime to use static import instead of dynamic import
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 17, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • Add sentry schema command for API introspection by BYK in #437

Bug Fixes 🐛

  • (dsn) Prevent hang during DSN auto-detection in repos with test fixtures by BYK in #445
  • (upgrade) Remove hard chain depth cap for nightly delta upgrades by BYK in #444

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 17, 2026

Codecov Results 📊

111 passed | Total: 111 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

✅ Patch coverage is 93.85%. Project has 1076 uncovered lines.
✅ Project coverage is 95.24%. Comparing base (base) to head (head).

Files with missing lines (2)
File Patch % Lines
resolve-target.ts 82.72% ⚠️ 117 Missing
code-scanner.ts 98.20% ⚠️ 6 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    95.24%    95.24%        —%
==========================================
  Files          167       167         —
  Lines        22542     22602       +60
  Branches         0         0         —
==========================================
+ Hits         21469     21526       +57
- Misses        1073      1076        +3
- Partials         0         0         —

Generated by Codecov Action

@BYK BYK marked this pull request as ready for review March 17, 2026 12:05
- Rename regionPromises → regionCache (BYK suggestion)
- Evict rejected promises from regionCache via .catch handler
  so retries after re-authentication work (Seer + BugBot)
- Use limit.map helper instead of manual map + Promise.all (BYK)
- Replace setTimeout + Promise.race with AbortSignal.timeout —
  self-cleaning, doesn't hold event loop (BYK + BugBot)
- Queued tasks check signal.aborted before work (code-scanner
  earlyExit pattern from PR #414)
- Take AGENTS.md from origin/main to resolve merge conflict
Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

The AbortSignal.timeout only prevents queued tasks from starting but
doesn't abort already in-flight HTTP requests. Race limit.map against
the abort signal so the function returns on timeout even if some tasks
are still running. Results are written to a shared array so partial
results survive the race.
@BYK BYK merged commit dfc2100 into main Mar 17, 2026
22 checks passed
@BYK BYK deleted the fix/dsn-discovery-hang branch March 17, 2026 12:57
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