Commit fc9444f
committed
inspector: avoid v8::String allocation in fromStringView
fromStringView() was round-tripping the inspector StringView through
v8::String::NewFromOneByte / NewFromTwoByte just to use Utf8Value for
the UTF-16 to UTF-8 conversion. That allocation is into V8's managed
heap, which is forbidden during certain V8 internal phases -- most
notably weak callbacks during garbage collection.
The concrete failure path that motivated this fix:
v8::internal::HeapAllocator::AllocateRaw (debug check)
v8::String::NewFromOneByte
fromStringView
v8_inspector__Channel__IMPL::sendResponse
v8_crdtp::DomainDispatcher::sendResponse
v8_inspector::EvaluateCallback::sendFailure
v8_inspector::PromiseHandlerTracker::sendFailure
v8_inspector::PromiseHandlerTracker::discard
v8::internal::GlobalHandles::InvokeFirstPassWeakCallbacks
v8::internal::Heap::PerformGarbageCollection
V8 invokes inspector callbacks (specifically
PromiseHandlerTracker::discard, which sends a failure response for a
stale Runtime.evaluate) from inside GC's first-pass weak-callbacks
phase. Sending the response goes through this helper; the
v8::String::NewFromOneByte allocation then trips
AllowHeapAllocation::IsAllowed() and aborts the process in debug
builds (in release builds it's undefined behavior, since allocations
during weak callbacks can corrupt the heap walk).
The conversion doesn't actually need V8 at all -- it's just bytes in,
UTF-8 bytes out. Use the same approach allocString() already uses
(the call site immediately below this one in the file): direct
construction of std::string for the 8-bit case, v8_inspector::UTF16ToUTF8
for the 16-bit case. v8_inspector::UTF16ToUTF8 is a pure host-side
helper that doesn't touch the V8 heap.
The isolate parameter is kept for API compatibility but is no longer
referenced.
Reproduces with lightpanda-io/browser#2407 (puppeteer-core repro
against any iframe-heavy page that runs Web Workers; the inspector
keeps a Runtime.evaluate callback alive past the worker / page
lifetime, GC eventually fires the discard, and the v8::String
allocation aborts the process). With this change, the same 25-iteration
back-to-back stress test runs to completion without the V8 fatal.1 parent 0eef7f5 commit fc9444f
1 file changed
Lines changed: 29 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2440 | 2440 | | |
2441 | 2441 | | |
2442 | 2442 | | |
2443 | | - | |
2444 | | - | |
2445 | | - | |
2446 | | - | |
2447 | | - | |
2448 | | - | |
2449 | | - | |
2450 | | - | |
| 2443 | + | |
| 2444 | + | |
| 2445 | + | |
| 2446 | + | |
| 2447 | + | |
| 2448 | + | |
| 2449 | + | |
| 2450 | + | |
| 2451 | + | |
| 2452 | + | |
| 2453 | + | |
| 2454 | + | |
| 2455 | + | |
| 2456 | + | |
| 2457 | + | |
| 2458 | + | |
| 2459 | + | |
| 2460 | + | |
| 2461 | + | |
| 2462 | + | |
| 2463 | + | |
| 2464 | + | |
| 2465 | + | |
| 2466 | + | |
| 2467 | + | |
| 2468 | + | |
| 2469 | + | |
| 2470 | + | |
| 2471 | + | |
2451 | 2472 | | |
2452 | 2473 | | |
2453 | 2474 | | |
| |||
0 commit comments