Skip to content

Conversation

@ghostwriternr
Copy link
Member

Summary

Fixes race condition in getExecutorLock() where concurrent calls could create duplicate mutex instances, defeating serialization. Also fixes memory leak where executor mutexes weren't cleaned up on process exit.

Test plan

  • E2E tests pass locally
  • Improved isolation test now verifies state across 12 contexts using globalThis

@changeset-bot
Copy link

changeset-bot bot commented Nov 26, 2025

🦋 Changeset detected

Latest commit: 9ceaa8e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cloudflare/sandbox Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 26, 2025

Open in StackBlitz

npm i https://pkg.pr.new/cloudflare/sandbox-sdk/@cloudflare/sandbox@258

commit: 9ceaa8e

@github-actions
Copy link
Contributor

github-actions bot commented Nov 26, 2025

🐳 Docker Image Published

FROM cloudflare/sandbox:0.0.0-pr-258-2e2af2d

Version: 0.0.0-pr-258-2e2af2d

You can use this Docker image with the preview package from this PR.

claude[bot]

This comment was marked as outdated.

@ghostwriternr
Copy link
Member Author

@claude can you fix the issues raised in the code review comments

@claude
Copy link
Contributor

claude bot commented Nov 26, 2025

Claude finished @ghostwriternr's task —— View job


Fixed Code Review Issues ✓

All three issues from the code review have been fixed and pushed:

Changes Made

  1. Critical Issue Version Packages #1 - Missing mutex cleanup in cleanupIdleProcesses() (line 675)

    • Added this.executorLocks.delete(process.id) after killing idle processes
    • Prevents memory leak when idle executors are cleaned up
  2. Critical Issue Version Packages #2 - Missing mutex cleanup in shutdown() (line 763)

    • Added this.executorLocks.clear() at the end of shutdown
    • Ensures all executor locks are cleaned up on shutdown
  3. Minor Issue - Misleading comment in releaseExecutorForContext() (line 563)

    • Changed comment from "Remove exit handler to prevent memory leak" to "Remove exit handler since we're doing manual cleanup"
    • Better reflects the actual purpose of removing the handler

Verification

  • ✅ TypeScript compilation passes
  • ✅ All unit tests pass (292 tests in sandbox package, 427 tests in container package)
  • ✅ Changes committed and pushed to interpreter-fixes-cleanup branch

The memory leak fixes are now complete. The mutex cleanup now happens in all process termination paths:

  • Unexpected process exit (via exit handler)
  • Manual context release
  • Idle process cleanup
  • System shutdown

--- | Branch: interpreter-fixes-cleanup

Added executorLocks.delete() calls in cleanupIdleProcesses() and
shutdown() to prevent memory leaks. Also clarified comment in
releaseExecutorForContext().

Co-authored-by: Naresh <[email protected]>
claude[bot]

This comment was marked as outdated.

@ghostwriternr ghostwriternr merged commit 34bfb81 into main Nov 26, 2025
12 of 13 checks passed
@ghostwriternr ghostwriternr deleted the interpreter-fixes-cleanup branch November 26, 2025 20:16
@github-actions github-actions bot mentioned this pull request Nov 26, 2025
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