Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using the Node.js inspector can lead to a crash #103

Open
mmomtchev opened this issue Oct 29, 2023 · 3 comments
Open

Using the Node.js inspector can lead to a crash #103

mmomtchev opened this issue Oct 29, 2023 · 3 comments

Comments

@mmomtchev
Copy link
Owner

mmomtchev commented Oct 29, 2023

When using the Node.js inspector to step over the final iteration of a loop iterating over a Python iterable, when Python throws the final exception, V8 crashes.

Seems to happen only in async contexts.

The crash is caused by V8 unable to identify the correct handler to step over.

Python exception: <NULL> @ C:\Users\mmom\src\pymport\src\call.cc:265


#
# Fatal error in , line 0
# Check failed: CodeKind::INTERPRETED_FUNCTION == code->kind().
#
#
#
#FailureMessage Object: 000000E8F97FAF20
 1: 00007FF66A0A9E7F node_api_throw_syntax_error+175967
 2: 00007FF669FC036F v8::CTypeInfoBuilder<void>::Build+11999
 3: 00007FF66AE2D182 V8_Fatal+162
 4: 00007FF66A9F29E5 v8::internal::Debug::PrepareStepOnThrow+1253
 5: 00007FF66A9F1099 v8::internal::Debug::OnThrow+345
 6: 00007FF66A9A51D0 v8::internal::Isolate::ThrowInternal+544
 7: 00007FF66A9A4059 v8::internal::Isolate::ScheduleThrow+25
 8: 00007FF66AAD1CCB v8::Isolate::ThrowException+59
 9: 00007FF66A07DF17 napi_throw+119
10: 00007FFDC38E642C Napi::Error::ThrowAsJavaScriptException+188 [C:\Users\mmom\src\pymport\node_modules\node-addon-api\napi-inl.h]:L2408
11: 00007FFDC39C29C7 `Napi::details::WrapCallback<<lambda_484baa0b744a2c3b2bec5c95d3446a94> >'::`1'::catch$0+103 [C:\Users\mmom\src\pymport\node_modules\node-addon-api\napi-inl.h]:L65
12: 00007FFDC394D3F0 _CallSettingFrame_LookupContinuationIndex+32 [D:\a\_work\1\s\src\vctools\crt\vcruntime\src\eh\amd64\handlers.asm]:L98
13: 00007FFDC394B51E __FrameHandler4::CxxCallCatchBlock+478 [D:\a\_work\1\s\src\vctools\crt\vcruntime\src\eh\frame.cpp]:L1439
14: 00007FFDF2E33CE6 RtlCaptureContext2+1190
15: 00007FFDC38F9B75 Napi::details::WrapCallback<<lambda_484baa0b744a2c3b2bec5c95d3446a94> >+53 [C:\Users\mmom\src\pymport\node_modules\node-addon-api\napi-inl.h]:L60
16: 00007FFDC38F86E0 Napi::InstanceWrap<pymport::PyObjectWrap>::InstanceMethodCallbackWrapper+64 [C:\Users\mmom\src\pymport\node_modules\node-addon-api\napi-inl.h]:L3463
17: 00007FF66A0760B0 cppgc::internal::BaseSpace::pages_mutex+32752
18: 00007FF66AAECAE2 v8::internal::SetupIsolateDelegate::SetupHeap+54946
19: 00007FF5EB0FB5C4
@mmomtchev
Copy link
Owner Author

mmomtchev commented Oct 29, 2023

Possible workarounds:

  • Do not use proxified iterators
  • Do not use for (const XX of YY) loops because Python exits this loop by throwing an exception
  • Simply set a breakpoint after the loop

This bug impacts only stepping over the loop with a debugger - it does not happen in any other case

@mmomtchev
Copy link
Owner Author

Suspected to be related to the double throw coming from Node-API

@mmomtchev
Copy link
Owner Author

Another workaround is to simply set up a manual breakpoint in the iterator on this line (the line that throws when the end of the iterable is reached):

const el = py_next.call();

Once this breakpoint has been triggered, the V8 debugger will correctly identify the source of the exception and won't crash - even if the breakpoint is removed.

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

No branches or pull requests

1 participant