Skip to content

fix: prevent pool corruption from undefined boxId - #6

Merged
cryptomafiaPB merged 2 commits into
mainfrom
fix/pool-corruption-undefined-boxid
Jun 7, 2026
Merged

fix: prevent pool corruption from undefined boxId#6
cryptomafiaPB merged 2 commits into
mainfrom
fix/pool-corruption-undefined-boxid

Conversation

@ombagal777

Copy link
Copy Markdown
Collaborator

Problem

If pool.acquireBox() throws an error (e.g., HTTP_429), the finally block
still executes and calls pool.releaseBox(boxId) where boxId is undefined.
This pushes undefined into the availableBoxIds array, corrupting the pool.

Solution

Guard the releaseBox call with an undefined check.

…finally block

- Guard pool.releaseBox() call with undefined check
- Prevents undefined values from being pushed to availableBoxIds array
- Fixes issue where HTTP_429 or other early errors could corrupt the box ID pool

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to prevent pool.releaseBox(...) from being called with an undefined boxId during request cleanup in the /api/v1/execute handler, avoiding corruption of the pool’s available box ID list.

Changes:

  • Adds an explicit boxId !== undefined guard around the isolate cleanup and pool.releaseBox(boxId) call in the handler’s finally block.
  • Nests the cleanup/release logic under the new guard to avoid operating on an uninitialized box ID.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

pool.releaseBox(boxId);
} catch (cleanupError) {
fastify.log.error(`Failed to cleanup box ${boxId}: ${cleanupError}`);
if (boxId !== undefined) {
Comment thread packages/api/src/server.ts

@cryptomafiaPB cryptomafiaPB left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The fix correctly avoids changing pool.releaseBox with undefined boxId, which would corrupt the pool state.

Overall, the changes looks good and address the issue/bug "[BUG] boxId Used Uninitialized in finally — Pool Corruption #5 ".

Improved workflow and added `pool.releaseBox(boxId)` in new finally block.
Which ensures `boxId` does get released.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@cryptomafiaPB
cryptomafiaPB merged commit af869db into main Jun 7, 2026
9 checks passed
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.

3 participants