Fix crash when destroying Wrappables after isolate shutdown#6052
Merged
Fix crash when destroying Wrappables after isolate shutdown#6052
Conversation
kentonv
reviewed
Feb 11, 2026
kentonv
approved these changes
Feb 11, 2026
Member
kentonv
left a comment
There was a problem hiding this comment.
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.
3bd4404 to
1e640f5
Compare
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.
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.