Skip to content

Stepping through for...of header crashes the inspector #58570

@Zirak

Description

@Zirak

Version

v24.1.0

Replicates in v23.11.1, v23.1.0, does not replicate in v22.16.0

Platform

Darwin macs-MacBook-Pro.local 23.6.0 Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:30 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6030 arm64

Replicates in

Linux dell 6.8.0-57-generic #59~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Mar 19 17:07:41 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

inspector

What steps will reproduce the bug?

Install opentelemetry's autoinstrumentation package and do the most minimal setup:

~/work/inspector-node-crash-otel
❯ cat package.json
{
  "dependencies": {
    "@opentelemetry/auto-instrumentations-node": "0.60.0"
  }
}

~/work/inspector-node-crash-otel
❯ cat crash.js
const { NodeSDK } = require('@opentelemetry/sdk-node');
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');

const sdk = new NodeSDK({
    instrumentations: getNodeAutoInstrumentations(),
});

sdk.start();

Run with the inspector:

node --inspect-brk crash.js

Add a breakpoint on opentelemetry/instrumentation/src/platform/node/instrumentation.ts line 288:

    this._warnOnPreloadedModules();
    for (const module of this._modules) {                    // <--- HERE
      const hookFn: HookFn = (exports, name, baseDir) => {

Continue execution, letting the breakpoint hit. Then hit "next" (F10) to step into the loop. Weep internally.

How often does it reproduce? Is there a required condition?

Tried 10 times, reproduced 10 times

What is the expected behavior? Why is that the expected behavior?

Code continues being debugged

What do you see instead?

#
# Fatal error in , line 0
# Check failed: needs_context && current_scope_ == closure_scope_ && current_scope_->is_function_scope() && !function_.is_null() implies function_->context() != *context_.
#
#
#
#FailureMessage Object: 0x16b89b258
----- Native stack trace -----

 1: 0x10468fbd0 node::NodePlatform::GetStackTracePrinter()::$_0::__invoke() [/opt/homebrew/Cellar/node/24.1.0/bin/node]
 2: 0x105519090 V8_Fatal(char const*, ...) [/opt/homebrew/Cellar/node/24.1.0/bin/node]
 3: 0x10489933c v8::internal::ScopeIterator::AdvanceOneScope() [/opt/homebrew/Cellar/node/24.1.0/bin/node]
 4: 0x10489987c v8::internal::ScopeIterator::VisitLocalScope(std::__1::function<bool (v8::internal::Handle<v8::internal::String>, v8::internal::Handle<v8::internal::Object>, v8::internal::ScopeIterator::ScopeType)> const&, v8::internal::ScopeIterator::Mode, v8::internal::ScopeIterator::ScopeType) const [/opt/homebrew/Cellar/node/24.1.0/bin/node]
 5: 0x104898fc4 v8::internal::ScopeIterator::ScopeObject(v8::internal::ScopeIterator::Mode) [/opt/homebrew/Cellar/node/24.1.0/bin/node]
 6: 0x104d85410 v8_inspector::V8DebuggerAgentImpl::currentCallFrames(std::__1::unique_ptr<std::__1::vector<std::__1::unique_ptr<v8_inspector::protocol::Debugger::CallFrame, std::__1::default_delete<v8_inspector::protocol::Debugger::CallFrame>>, std::__1::allocator<std::__1::unique_ptr<v8_inspector::protocol::Debugger::CallFrame, std::__1::default_delete<v8_inspector::protocol::Debugger::CallFrame>>>>, std::__1::default_delete<std::__1::vector<std::__1::unique_ptr<v8_inspector::protocol::Debugger::CallFrame, std::__1::default_delete<v8_inspector::protocol::Debugger::CallFrame>>, std::__1::allocator<std::__1::unique_ptr<v8_inspector::protocol::Debugger::CallFrame, std::__1::default_delete<v8_inspector::protocol::Debugger::CallFrame>>>>>>*) [/opt/homebrew/Cellar/node/24.1.0/bin/node]
 7: 0x104d7ddd4 v8_inspector::V8DebuggerAgentImpl::didPause(int, v8::Local<v8::Value>, std::__1::vector<int, std::__1::allocator<int>> const&, v8::debug::ExceptionType, bool, v8::base::EnumSet<v8::debug::BreakReason, int>) [/opt/homebrew/Cellar/node/24.1.0/bin/node]
 8: 0x104d9adc4 v8_inspector::V8InspectorImpl::forEachSession(int, std::__1::function<void (v8_inspector::V8InspectorSessionImpl*)> const&) [/opt/homebrew/Cellar/node/24.1.0/bin/node]
 9: 0x104d8dad4 v8_inspector::V8Debugger::handleProgramBreak(v8::Local<v8::Context>, v8::Local<v8::Value>, std::__1::vector<int, std::__1::allocator<int>> const&, v8::base::EnumSet<v8::debug::BreakReason, int>, v8::debug::ExceptionType, bool) [/opt/homebrew/Cellar/node/24.1.0/bin/node]
10: 0x10489e83c v8::internal::Debug::OnDebugBreak(v8::internal::DirectHandle<v8::internal::FixedArray>, v8::internal::StepAction, v8::base::EnumSet<v8::debug::BreakReason, int>) [/opt/homebrew/Cellar/node/24.1.0/bin/node]
11: 0x10489e1ec v8::internal::Debug::Break(v8::internal::JavaScriptFrame*, v8::internal::DirectHandle<v8::internal::JSFunction>) [/opt/homebrew/Cellar/node/24.1.0/bin/node]
12: 0x104cf8328 v8::internal::Runtime_DebugBreakOnBytecode(int, unsigned long*, v8::internal::Isolate*) [/opt/homebrew/Cellar/node/24.1.0/bin/node]
13: 0x1052061f4 Builtins_CEntry_Return2_ArgvOnStack_NoBuiltinExit [/opt/homebrew/Cellar/node/24.1.0/bin/node]
14: 0x1052e3708 Builtins_DebugBreak3Handler [/opt/homebrew/Cellar/node/24.1.0/bin/node]
15: 0x105168bec Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node/24.1.0/bin/node]
16: 0x105168bec Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node/24.1.0/bin/node]
17: 0x105169400 Builtins_InterpreterPushArgsThenFastConstructFunction [/opt/homebrew/Cellar/node/24.1.0/bin/node]
18: 0x1052f8d28 Builtins_ConstructHandler [/opt/homebrew/Cellar/node/24.1.0/bin/node]
19: 0x105168bec Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node/24.1.0/bin/node]
20: 0x105169400 Builtins_InterpreterPushArgsThenFastConstructFunction [/opt/homebrew/Cellar/node/24.1.0/bin/node]
21: 0x1052f8d28 Builtins_ConstructHandler [/opt/homebrew/Cellar/node/24.1.0/bin/node]
22: 0x105168bec Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node/24.1.0/bin/node]
23: 0x105168bec Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node/24.1.0/bin/node]
24: 0x1051668cc Builtins_JSEntryTrampoline [/opt/homebrew/Cellar/node/24.1.0/bin/node]
25: 0x105166570 Builtins_JSEntry [/opt/homebrew/Cellar/node/24.1.0/bin/node]
26: 0x1048f1d20 v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [/opt/homebrew/Cellar/node/24.1.0/bin/node]
27: 0x1048f172c v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal::DirectHandle<v8::internal::Object>, v8::internal::DirectHandle<v8::internal::Object>, v8::base::Vector<v8::internal::DirectHandle<v8::internal::Object> const>) [/opt/homebrew/Cellar/node/24.1.0/bin/node]
28: 0x1047bfba0 v8::Function::Call(v8::Isolate*, v8::Local<v8::Context>, v8::Local<v8::Value>, int, v8::Local<v8::Value>*) [/opt/homebrew/Cellar/node/24.1.0/bin/node]
29: 0x10473fdb8 node::inspector::(anonymous namespace)::CallAndPauseOnStart(v8::FunctionCallbackInfo<v8::Value> const&) [/opt/homebrew/Cellar/node/24.1.0/bin/node]
30: 0x10516a818 Builtins_CallApiCallbackGeneric [/opt/homebrew/Cellar/node/24.1.0/bin/node]
31: 0x105168bec Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node/24.1.0/bin/node]
32: 0x105168bec Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node/24.1.0/bin/node]
33: 0x105168bec Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node/24.1.0/bin/node]
34: 0x105168bec Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node/24.1.0/bin/node]
35: 0x105168bec Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node/24.1.0/bin/node]
36: 0x105168bec Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node/24.1.0/bin/node]
37: 0x105168bec Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node/24.1.0/bin/node]
38: 0x105168bec Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node/24.1.0/bin/node]
39: 0x1051668cc Builtins_JSEntryTrampoline [/opt/homebrew/Cellar/node/24.1.0/bin/node]
40: 0x105166570 Builtins_JSEntry [/opt/homebrew/Cellar/node/24.1.0/bin/node]
41: 0x1048f1d20 v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [/opt/homebrew/Cellar/node/24.1.0/bin/node]
42: 0x1048f172c v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal::DirectHandle<v8::internal::Object>, v8::internal::DirectHandle<v8::internal::Object>, v8::base::Vector<v8::internal::DirectHandle<v8::internal::Object> const>) [/opt/homebrew/Cellar/node/24.1.0/bin/node]
43: 0x1047bfba0 v8::Function::Call(v8::Isolate*, v8::Local<v8::Context>, v8::Local<v8::Value>, int, v8::Local<v8::Value>*) [/opt/homebrew/Cellar/node/24.1.0/bin/node]
44: 0x104609708 node::builtins::BuiltinLoader::CompileAndCall(v8::Local<v8::Context>, char const*, node::Realm*) [/opt/homebrew/Cellar/node/24.1.0/bin/node]
45: 0x10469d818 node::Realm::ExecuteBootstrapper(char const*) [/opt/homebrew/Cellar/node/24.1.0/bin/node]
46: 0x1045ec818 node::StartExecution(node::Environment*, char const*) [/opt/homebrew/Cellar/node/24.1.0/bin/node]
47: 0x1045ec794 node::StartExecution(node::Environment*, std::__1::function<v8::MaybeLocal<v8::Value> (node::StartExecutionCallbackInfo const&)>) [/opt/homebrew/Cellar/node/24.1.0/bin/node]
48: 0x10456cfdc node::LoadEnvironment(node::Environment*, std::__1::function<v8::MaybeLocal<v8::Value> (node::StartExecutionCallbackInfo const&)>, std::__1::function<void (node::Environment*, v8::Local<v8::Value>, v8::Local<v8::Value>)>) [/opt/homebrew/Cellar/node/24.1.0/bin/node]
49: 0x10466729c node::NodeMainInstance::Run(node::ExitCode*, node::Environment*) [/opt/homebrew/Cellar/node/24.1.0/bin/node]
50: 0x104667074 node::NodeMainInstance::Run() [/opt/homebrew/Cellar/node/24.1.0/bin/node]
51: 0x1045ef250 node::Start(int, char**) [/opt/homebrew/Cellar/node/24.1.0/bin/node]
52: 0x1951ab154 start [/usr/lib/dyld]
fish: Job 1, 'node --inspect-brk crash.js' terminated by signal SIGTRAP (Trace or breakpoint trap

Reproduces when building from main:

~/sources/node/out/Debug/node --inspect-brk crash.js
Debugger listening on ws://127.0.0.1:9229/90464ca5-6eba-4444-9575-d3a43b98ce9d
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.


#
# Fatal error in ../deps/v8/src/debug/debug-scopes.cc, line 569
# Debug check failed: NeedsContext() implies context_->IsBlockContext().
#
#
#
#FailureMessage Object: 0x16ae0ea68
----- Native stack trace -----

 1: 0x1050cc264 node::DumpNativeBacktrace(__sFILE*) [/Users/zirak/sources/node/out/Debug/node]
 2: 0x105365654 node::NodePlatform::GetStackTracePrinter()::$_0::operator()() const [/Users/zirak/sources/node/out/Debug/node]
 3: 0x105365610 node::NodePlatform::GetStackTracePrinter()::$_0::__invoke() [/Users/zirak/sources/node/out/Debug/node]
 4: 0x107e86560 V8_Fatal(char const*, int, char const*, ...) [/Users/zirak/sources/node/out/Debug/node]
 5: 0x107e85ed0 v8::base::SetFatalFunction(void (*)(char const*, int, char const*)) [/Users/zirak/sources/node/out/Debug/node]
 6: 0x105970154 v8::internal::ScopeIterator::Type() const [/Users/zirak/sources/node/out/Debug/node]
 7: 0x10596d050 v8::internal::DebugScopeIterator::DebugScopeIterator(v8::internal::Isolate*, v8::internal::FrameInspector*) [/Users/zirak/sources/node/out/Debug/node]
 8: 0x105977578 v8::internal::DebugStackTraceIterator::GetScopeIterator() const [/Users/zirak/sources/node/out/Debug/node]
 9: 0x10650ca38 v8_inspector::V8DebuggerAgentImpl::currentCallFrames(std::__1::unique_ptr<std::__1::vector<std::__1::unique_ptr<v8_inspector::protocol::Debugger::CallFrame, std::__1::default_delete<v8_inspector::protocol::Debugger::CallFrame>>, std::__1::allocator<std::__1::unique_ptr<v8_inspector::protocol::Debugger::CallFrame, std::__1::default_delete<v8_inspector::protocol::Debugger::CallFrame>>>>, std::__1::default_delete<std::__1::vector<std::__1::unique_ptr<v8_inspector::protocol::Debugger::CallFrame, std::__1::default_delete<v8_inspector::protocol::Debugger::CallFrame>>, std::__1::allocator<std::__1::unique_ptr<v8_inspector::protocol::Debugger::CallFrame, std::__1::default_delete<v8_inspector::protocol::Debugger::CallFrame>>>>>>*) [/Users/zirak/sources/node/out/Debug/node]
10: 0x106503080 v8_inspector::V8DebuggerAgentImpl::didPause(int, v8::Local<v8::Value>, std::__1::vector<int, std::__1::allocator<int>> const&, v8::debug::ExceptionType, bool, v8::base::EnumSet<v8::debug::BreakReason, int>) [/Users/zirak/sources/node/out/Debug/node]
11: 0x106526af0 v8_inspector::V8InspectorImpl::forEachSession(int, std::__1::function<void (v8_inspector::V8InspectorSessionImpl*)> const&) [/Users/zirak/sources/node/out/Debug/node]
12: 0x1065173b4 v8_inspector::V8Debugger::handleProgramBreak(v8::Local<v8::Context>, v8::Local<v8::Value>, std::__1::vector<int, std::__1::allocator<int>> const&, v8::base::EnumSet<v8::debug::BreakReason, int>, v8::debug::ExceptionType, bool) [/Users/zirak/sources/node/out/Debug/node]
13: 0x10597dc2c v8::internal::Debug::OnDebugBreak(v8::internal::DirectHandle<v8::internal::FixedArray>, v8::internal::StepAction, v8::base::EnumSet<v8::debug::BreakReason, int>) [/Users/zirak/sources/node/out/Debug/node]
14: 0x10597cdb0 v8::internal::Debug::Break(v8::internal::JavaScriptFrame*, v8::internal::DirectHandle<v8::internal::JSFunction>) [/Users/zirak/sources/node/out/Debug/node]
15: 0x1063da324 v8::internal::Runtime_DebugBreakOnBytecode(int, unsigned long*, v8::internal::Isolate*) [/Users/zirak/sources/node/out/Debug/node]
16: 0x106ffe314 Builtins_CEntry_Return2_ArgvOnStack_NoBuiltinExit [/Users/zirak/sources/node/out/Debug/node]
17: 0x10712a348 Builtins_DebugBreak3Handler [/Users/zirak/sources/node/out/Debug/node]
18: 0x106f4866c Builtins_InterpreterEntryTrampoline [/Users/zirak/sources/node/out/Debug/node]
19: 0x106f4866c Builtins_InterpreterEntryTrampoline [/Users/zirak/sources/node/out/Debug/node]
20: 0x106f48e80 Builtins_InterpreterPushArgsThenFastConstructFunction [/Users/zirak/sources/node/out/Debug/node]
21: 0x107142a44 Builtins_ConstructHandler [/Users/zirak/sources/node/out/Debug/node]
22: 0x106f4866c Builtins_InterpreterEntryTrampoline [/Users/zirak/sources/node/out/Debug/node]
23: 0x106f48e80 Builtins_InterpreterPushArgsThenFastConstructFunction [/Users/zirak/sources/node/out/Debug/node]
24: 0x107142a44 Builtins_ConstructHandler [/Users/zirak/sources/node/out/Debug/node]
25: 0x106f4866c Builtins_InterpreterEntryTrampoline [/Users/zirak/sources/node/out/Debug/node]
26: 0x106f4866c Builtins_InterpreterEntryTrampoline [/Users/zirak/sources/node/out/Debug/node]
27: 0x106f456ac Builtins_JSEntryTrampoline [/Users/zirak/sources/node/out/Debug/node]
28: 0x106f45350 Builtins_JSEntry [/Users/zirak/sources/node/out/Debug/node]
29: 0x105a28818 v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [/Users/zirak/sources/node/out/Debug/node]
30: 0x105a27868 v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal::DirectHandle<v8::internal::Object>, v8::internal::DirectHandle<v8::internal::Object>, v8::base::Vector<v8::internal::DirectHandle<v8::internal::Object> const>) [/Users/zirak/sources/node/out/Debug/node]
31: 0x105690370 v8::Function::Call(v8::Isolate*, v8::Local<v8::Context>, v8::Local<v8::Value>, int, v8::Local<v8::Value>*) [/Users/zirak/sources/node/out/Debug/node]
32: 0x105531cb4 node::inspector::(anonymous namespace)::CallAndPauseOnStart(v8::FunctionCallbackInfo<v8::Value> const&) [/Users/zirak/sources/node/out/Debug/node]
33: 0x106f4a298 Builtins_CallApiCallbackGeneric [/Users/zirak/sources/node/out/Debug/node]
34: 0x106f4866c Builtins_InterpreterEntryTrampoline [/Users/zirak/sources/node/out/Debug/node]
35: 0x106f4866c Builtins_InterpreterEntryTrampoline [/Users/zirak/sources/node/out/Debug/node]
36: 0x106f4866c Builtins_InterpreterEntryTrampoline [/Users/zirak/sources/node/out/Debug/node]
37: 0x106f4866c Builtins_InterpreterEntryTrampoline [/Users/zirak/sources/node/out/Debug/node]
38: 0x106f4866c Builtins_InterpreterEntryTrampoline [/Users/zirak/sources/node/out/Debug/node]
39: 0x106f4866c Builtins_InterpreterEntryTrampoline [/Users/zirak/sources/node/out/Debug/node]
40: 0x106f4866c Builtins_InterpreterEntryTrampoline [/Users/zirak/sources/node/out/Debug/node]
41: 0x106f4866c Builtins_InterpreterEntryTrampoline [/Users/zirak/sources/node/out/Debug/node]
42: 0x106f456ac Builtins_JSEntryTrampoline [/Users/zirak/sources/node/out/Debug/node]
43: 0x106f45350 Builtins_JSEntry [/Users/zirak/sources/node/out/Debug/node]
44: 0x105a28818 v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [/Users/zirak/sources/node/out/Debug/node]
45: 0x105a27868 v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal::DirectHandle<v8::internal::Object>, v8::internal::DirectHandle<v8::internal::Object>, v8::base::Vector<v8::internal::DirectHandle<v8::internal::Object> const>) [/Users/zirak/sources/node/out/Debug/node]
46: 0x105690370 v8::Function::Call(v8::Isolate*, v8::Local<v8::Context>, v8::Local<v8::Value>, int, v8::Local<v8::Value>*) [/Users/zirak/sources/node/out/Debug/node]
47: 0x1051e67a0 node::builtins::BuiltinLoader::CompileAndCall(v8::Local<v8::Context>, char const*, int, v8::Local<v8::Value>*, node::Realm*) [/Users/zirak/sources/node/out/Debug/node]
48: 0x1051e6678 node::builtins::BuiltinLoader::CompileAndCall(v8::Local<v8::Context>, char const*, node::Realm*) [/Users/zirak/sources/node/out/Debug/node]
49: 0x105383e38 node::Realm::ExecuteBootstrapper(char const*) [/Users/zirak/sources/node/out/Debug/node]
50: 0x105197920 node::StartExecution(node::Environment*, char const*) [/Users/zirak/sources/node/out/Debug/node]
51: 0x1051977a4 node::StartExecution(node::Environment*, std::__1::function<v8::MaybeLocal<v8::Value> (node::StartExecutionCallbackInfo const&)>) [/Users/zirak/sources/node/out/Debug/node]
52: 0x105004d04 node::LoadEnvironment(node::Environment*, std::__1::function<v8::MaybeLocal<v8::Value> (node::StartExecutionCallbackInfo const&)>, std::__1::function<void (node::Environment*, v8::Local<v8::Value>, v8::Local<v8::Value>)>) [/Users/zirak/sources/node/out/Debug/node]
53: 0x1052d35dc node::NodeMainInstance::Run(node::ExitCode*, node::Environment*) [/Users/zirak/sources/node/out/Debug/node]
54: 0x1052d3268 node::NodeMainInstance::Run() [/Users/zirak/sources/node/out/Debug/node]
55: 0x10519a4e0 node::StartInternal(int, char**) [/Users/zirak/sources/node/out/Debug/node]
56: 0x10519a0fc node::Start(int, char**) [/Users/zirak/sources/node/out/Debug/node]
57: 0x10755c1c4 main [/Users/zirak/sources/node/out/Debug/node]
58: 0x1951ab154 start [/usr/lib/dyld]
fish: Job 1, '~/sources/node/out/Debug/node -…' terminated by signal SIGTRAP (Trace or breakpoint trap)

Additional information

This happens only when stepping through the loop header. When setting the breakpoint inside the loop body and hitting "Continue", the bug does not reproduce.

This happens both with and without source maps.

lmk if it's more appropriate to file as a v8 bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions