Skip to content

Fix crash when destroying Wrappables after isolate shutdown#6052

Merged
danlapid merged 1 commit intomainfrom
dlapid/fixSegfault
Feb 11, 2026
Merged

Fix crash when destroying Wrappables after isolate shutdown#6052
danlapid merged 1 commit intomainfrom
dlapid/fixSegfault

Conversation

@danlapid
Copy link
Copy Markdown
Collaborator

@danlapid danlapid commented Feb 11, 2026

When objects like WebSockets are stored in a HibernationManager, they can outlive their V8 isolate. Previously, when such objects were later destroyed, maybeDeferDestruction() would call v8::Locker::IsLocked() on a dangling isolate pointer, causing a segfault:

v8::Locker::IsLocked(isolate) // isolate is dangling

I think it's caused when detachWrapper() clears the wrapper-related state (wrapper, cppgcShim, strongWrapper) but leaves the isolate pointer intact. This is correct for normal GC where wrappers may be recreated, but during isolate shutdown the pointer becomes dangling.

The fix clears the isolate pointer in clearWrappers() after detaching each wrapper. This ensures that any code that later tries to use the isolate (maybeDeferDestruction, removeStrongRef, GcVisitor) will see isolate == nullptr and correctly skip V8 operations.

We clear the pointer in clearWrappers() rather than in detachWrapper() because detachWrapper() is also called during normal GC (when the isolate is still alive), and we need to preserve the isolate pointer in that case for potential wrapper recreation.

@danlapid danlapid requested review from a team as code owners February 11, 2026 00:32
Copy link
Copy Markdown
Member

@kentonv kentonv left a comment

Choose a reason for hiding this comment

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

Approved assuming the suggested change is applied.

When objects like WebSockets are stored in a HibernationManager, they
can outlive their V8 isolate. Previously, when such objects were later
destroyed, maybeDeferDestruction() would call v8::Locker::IsLocked()
on a dangling isolate pointer, causing a segfault:

  v8::Locker::IsLocked(isolate)  // isolate is dangling!

The root cause is that detachWrapper() clears the wrapper-related state
(wrapper, cppgcShim, strongWrapper) but leaves the isolate pointer
intact. This is correct for normal GC where wrappers may be recreated,
but during isolate shutdown the pointer becomes dangling.

The fix clears the isolate pointer in clearWrappers() after detaching
each wrapper. This ensures that any code that later tries to use the
isolate (maybeDeferDestruction, removeStrongRef, GcVisitor) will see
isolate == nullptr and correctly skip V8 operations.

We clear the pointer in clearWrappers() rather than in detachWrapper()
because detachWrapper() is also called during normal GC (when the
isolate is still alive), and we need to preserve the isolate pointer
in that case for potential wrapper recreation.
@danlapid danlapid enabled auto-merge February 11, 2026 01:48
@danlapid danlapid merged commit 9a08d8e into main Feb 11, 2026
34 of 35 checks passed
@danlapid danlapid deleted the dlapid/fixSegfault branch February 11, 2026 01:54
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.

2 participants