-
Notifications
You must be signed in to change notification settings - Fork 459
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
What if a thread-safe function execution throws an exception,FATAL ERROR: Error::Error napi_define_properties, I catch exceptions and exception handling calls Env interface GetAndClearPendingException, then submitted to the following error #1244
Comments
Hi there. Any chance you can provide a minimal reproducible example? (including the |
|
@JckXia ,Thank you for your reply, i use the node-addon-api version 5.0.0 write the addon plugin, and run in electron 18(Indicates the corresponding nodejs version 16.13.2), this isn't a problem that always comes up, but I've encountered it several times using the reload feature on my electron DevTools, what should i do? Here are the crash stack and thread-safe functions when an exception occurs |
Could you provide the source code of an addon that would best replicate this issue? Or would that not possible in this case? But just a shot in the dark...it looks like the real issue here is As you have mentioned it is an intermittent failure. Another option is to compile |
The following example can reproduce the crash, Hi, @jack
…------------------ 原始邮件 ------------------
发件人: "nodejs/node-addon-api" ***@***.***>;
发送时间: 2022年12月5日(星期一) 凌晨4:15
***@***.***>;
***@***.***>;"State ***@***.***>;
主题: Re: [nodejs/node-addon-api] What if a thread-safe function execution throws an exception,FATAL ERROR: Error::Error napi_define_properties, I catch exceptions and exception handling calls Env interface GetAndClearPendingException, then submitted to the following error (Issue #1244)
Could you provide the source code of an addon that would best replicate this issue? Or would that not possible in this case?
But just a shot in the dark...it looks like the real issue here is napi_set_named_property failed to define the property width on the videoFrame object. The macro in the following line simply wraps the error in an Napi::Object, where we do the error wrapping logic but napi_define_properties shouldn't fail.
As you have mentioned it is an intermittent failure. Another option is to compile node 16.33.2 from the source and put a debugger starting at this line: https://github.com/nodejs/node/blob/main/src/js_native_api_v8.cc#L1104 should the error persists.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you modified the open/close state.Message ID: ***@***.***>
|
Sorry, the format looked a bit funky to me. Is this a new example are you talking about, or is it the one in your original post? |
Sorry, that message was sent in the wrong format, @JckXia , Here is the addon implementation code I can reproduce for crash: #include <napi.h> class MyObjWrap : public Napi::ObjectWrap { public: private: }; class MyObjWrap1 : public Napi::ObjectWrap { public: private: }; Napi::ThreadSafeFunction myThreadFunction; bool isStop(true);
std::this_thread::sleep_for(std::chrono::microseconds(1)); void threadLoop2()
std::this_thread::sleep_for(std::chrono::microseconds(1)); class MyObjWrap2 : public Napi::ObjectWrap { public: private: }; class Addon : public Napi::Addon { Napi::Value CreateFunction(const Napi::CallbackInfo& info)
} Napi::Value CreateObject(const Napi::CallbackInfo& info)
} Addon(Napi::Env env, Napi::Object exports) { // The macro announces that instances of the class Here is the code I can reproduce for electron using addon:(render.js) //'use strict' To repeat the step, click the button on the electron interface and then click reload on Devtools and wait for a while to crash Judging by the results of my tests:I think when I click on the button in the electron (start threads and run thread-safe function), because the thread-safe function need to perform more tasks (may queue accumulation is too many tasks, not to be able to perform), and then led to a thread-safe function performs the exception, but what I don't really understand the underlying implementation of it @JckXia |
Ok thank you @Candylong. Will try to reproduce this on my end and get back to you asap. |
Hey @Candylong, there were some issues with the code you provided. I made some fixes and stored it under https://github.com/JckXia/napi-bug-repro. Just want to double check we are indeed able to reproduce the bug with this addon. I haven't used Out of curiosity, were you able to replicate this issue outside of the electron environment? Or does the error only show up when run in |
@JckXia ,like you said, normal operation will be fine, the main issue is to highlight the context-aware addon feature, while electron's reload will reload addon(.node) repeatedly,which is what context-aware addon supports(https://nodejs.org/dist/latest-v18.x/docs/api/addons.html#context-aware-addons), so it shouldn't be a problem I have arranged my demo and put it here(https://github.com/Candylong/napi-electron-demo). I mainly run it on windows, and it can be reproduced after about 5 operations. Can you have a try |
Hey @Candylong. I tried your code and can indeed replicate this bug (clicking the button in 5 rapid successions and then attempting to reload). Will take a deeper dive tomorrow. |
@JckXia ,Thank you very much and look forward to your reply. |
I did more testing with this addon, and here are some things I've noticed:
Hmm, any ideas? @nodejs/node-api |
On a side note, it appears the |
Hey@JckXia ,is there any progress on this problem? It seems that this problem is blocked at present. What should I do? |
Hey @Candylong, sorry haven't got much time to look at this. Still not too sure about the underlying mechanism that causes this but I suspect it has to do with how we are spawning the threads. But just some observations regarding the code you've provided. From what I understand, you want to tie the life cycle of Another thing that I've noticed is that perhaps the two threads are competing for resources. When I simply run one of the two threads, the crash still happens but doesn't get triggered as easily. Is there any way you could make use of condition variables to coordinate the execution of code in |
I did a quick proof of concept here: https://github.com/JckXia/napi-bug-repro/blob/main/example.cc for reference. |
@JckXia ,Thank you very much. But he reason why I used two threads to run was to simulate reproducing the crash problem(frequent callbacks using thread-safe functions). In the actual scenario, these threads were third-party library threads, I could not do this as you said. For example, reload should be executed into Hook (AddCleanupHook) first, and then I call the third-party library interface in the hook function to synchronously stop the threads. |
This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made. |
Does anyone know about this problem? |
@Candylong I just tried your demo. It says "We are using Node.js 18.12.1, Chromium 110.0.5481.208, and Electron 23.2.2." I pressed the button 5 times in quick succession then reloaded. It did not crash. Are you still seeing this problem> |
@gabrielschulhof ,Hi, Instead of clicking the button in quick succession, I clicked the button each time and then clicked reload on electron DevTools. My test probably crashed after clicking reload on electron DevTools 5 times(Click the button on the interface and click reload on the electron DevTools) |
@Candylong I'm not seeing a reload button on my devtools, except on the performance tab where I can reload and start recording. I tried to click the button and then press Ctrl+R, and that worked lots of times in succession. I may not be able to reproduce the problem because there's an error in the console during reload:
|
@gabrielschulhof , |
This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made. |
The text was updated successfully, but these errors were encountered: