Fix memory leaks and improve error handling#3
Open
hobostay wants to merge 1 commit intokessler:mainfrom
Open
Conversation
This commit addresses several reliability issues: 1. **Memory leak in pendingToolResults Map**: Tool execution promises now have a 30-second timeout and proper cleanup. Previously, if a tool execution failed or hung, the promise resolver would remain in the Map forever. 2. **Race condition in offscreen document creation**: If creating the offscreen document fails, the creating flag is now properly reset in a finally block, allowing subsequent calls to retry. 3. **Intl.DisplayNames error handling**: The getCountry() function now handles cases where Intl.DisplayNames.of() returns undefined or throws an exception. 4. **Improved tool execution error handling**: Tool execution errors are now caught and returned as proper error responses instead of causing unhandled promise rejections. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR addresses several reliability issues found in the codebase:
1. Memory leak in pendingToolResults Map
Problem: Tool execution promises had no timeout mechanism. If a tool execution failed or hung, the promise's resolve function would remain in the Map forever, causing a memory leak.
Fix:
2. Race condition in offscreen document creation
Problem: If creating the offscreen document failed in
background/offscreen-manager.ts, thecreatingPromise was never reset, causing subsequent calls to hang indefinitely.Fix: Wrapped the await in try-finally to ensure the
creatingflag is always reset, even if creation fails.3. Intl.DisplayNames error handling
Problem: The
getCountry()function inentrypoints/offscreen/main.tsdidn't handle cases whereIntl.DisplayNames.of()returnsundefinedor throws an exception for invalid region codes.Fix: Added try-catch block and proper null/undefined handling.
Testing
pnpm buildcompletes successfully🤖 Generated with Claude Code