← Back to PRs

#15948: fix(logging): prevent recursive logger/config stack overflow

by Glucksberg open 2026-02-14 03:11 View on GitHub →
size: S experienced-contributor
## Summary - add reentrancy guard in logger settings resolution to avoid recursive config load when console capture logs during config failures - ensure guard is always reset with a finally block and preserve Vitest default file-log level behavior - add regression test that reproduces circular-include config failure under console capture and asserts no stack overflow ## Validation - bun test src/logging/logger.import-side-effects.test.ts src/logging/logger.recursion-guard.test.ts src/index.test.ts --reporter=dot - pnpm exec oxlint src/logging/logger.ts src/logging/logger.recursion-guard.test.ts <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> Prevents recursive stack overflow in logger settings resolution when config loading fails under console capture. **Key changes:** - Added `resolvingSettings` reentrancy guard flag in `logger.ts:20` - Introduced `resolveFallbackSettings()` helper that returns safe defaults when recursion is detected - Wrapped `resolveSettings()` in try/finally to ensure guard is always reset - Added comprehensive regression test that reproduces circular `$include` failure scenario **How it works:** When console capture is enabled, console calls route through the file logger. If config loading fails and logs an error, that error would trigger another `getLogger()` call, creating infinite recursion. The guard detects reentry and returns fallback settings instead of recursing. **Impact:** This is a critical stability fix that prevents crashes during config loading failures, particularly in test environments with console capture enabled. <h3>Confidence Score: 5/5</h3> - Safe to merge - critical bug fix with no breaking changes - This is a well-implemented fix for a critical stack overflow bug. The reentrancy guard pattern is standard and correct, using try/finally ensures the guard is always reset, and the fallback settings provide safe defaults. The regression test directly reproduces the failure scenario with a circular $include. No logic changes to normal operation - only adds protection for the error path. - No files require special attention <sub>Last reviewed commit: 0d8f9f3</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs