Worker resourceLimits are not enforced while DevTools has the Debugger domain enabled

未關閉
#2,107 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
48/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
cpp

研究方向

Start in WorkerWrapper::OnNearHeapLimit and PrepareV8Runtime, then trace how the worker inspector session enables Debugger and how V8Debugger::enable and disable manage heap-limit callbacks. Reproduce with a debug build and a worker using resourceLimits; check that the parent receives the heap-limit error and the worker terminates after any intended debugger pause or resume.

由索引模型根據 Issue 內容生成。

描述

Summary

In a debug build, once a DevTools session enables the Debugger domain on a worker target, that worker's resourceLimits stop being enforced and the parent never receives the heap-limit error.

Why

WorkerWrapper::OnNearHeapLimit is registered with AddNearHeapLimitCallback in PrepareV8Runtime. It reports ERR_WORKER_OUT_OF_MEMORY to the parent and terminates the worker. V8 only invokes the most recently added near-heap-limit callback (Heap::InvokeNearHeapLimitCallback calls near_heap_limit_callbacks_.back(), src/heap/heap.cc). V8Debugger::enable adds its own callback (src/inspector/v8-debugger.cc), which shadows the worker's for as long as the Debugger domain stays enabled. That callback:

  • schedules an OOM break (BreakReason::kOOM), and
  • returns HeapLimitForDebugging(initial_heap_limit), which raises the limit well past the configured maxOldGenerationSizeMb.

So while a debugger is attached to the worker, the worker either pauses on OOM in DevTools or keeps running above its cap. Either way OnNearHeapLimit never runs: the parent gets no error event, terminate/exit never follow, and code that relies on resourceLimits to contain a runaway worker behaves differently under the debugger than without it. Detaching restores the worker's callback (V8Debugger::disable removes the debugger's).

Release builds are unaffected (no inspector), and so are debug builds with no DevTools session, or with one that never enables Debugger on the worker target.

Expected

Pausing on OOM while debugging is reasonable and matches Chrome. But after the user resumes (or if the debugger's raised limit is also exhausted), the worker should still be reported and terminated as it is without a debugger. Possible directions:

  • Re-register OnNearHeapLimit after the worker's inspector session enables Debugger, so it stays last, and decide explicitly whether to break first.
  • Or chain: keep the debugger's break, but have the worker's handler run on resume, or once the debug allowance is exhausted.
Repro (sketch)
  1. Debug build of an app with a worker created with resourceLimits: { maxOldGenerationSizeMb: 16 } whose script allocates until it runs out of memory.
  2. Without DevTools: the parent gets the heap-limit error, and the worker ends.
  3. Attach Chrome DevTools to the worker target (which enables Debugger) and rerun: no error reaches the parent. The worker pauses on OOM, or, after resuming, keeps allocating past 16 MB.

Found while reviewing #2070.

主要語言
C++
星號
565
分支
147
平均合併
1 天 2 小時
30 天內合併 PR
27

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

NativeScript/android 的其他 Issue

查看 NativeScript/android 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。