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

Error was ignored if ThreadSafeFunction::GetContext() failed #581

Closed
legendecas opened this issue Oct 31, 2019 · 5 comments · Fixed by #583
Closed

Error was ignored if ThreadSafeFunction::GetContext() failed #581

legendecas opened this issue Oct 31, 2019 · 5 comments · Fixed by #583

Comments

@legendecas
Copy link
Member

legendecas commented Oct 31, 2019

Currently napi_status was ignored in ThreadSafeFunction::GetContext(). No napi_status shall be ignored as it would unstablize the behavior we'd expect.

Since the function signature doesn't support error returning, an alternative might be aborting on non-napi_ok statuses.

Originally posted by @legendecas in #546

@KevinEady
Copy link
Contributor

Hi team,

I can start work on this if nobody has? (direct ping to @legendecas since he reported this)

@legendecas
Copy link
Member Author

@KevinEady You have it. :P

@KevinEady
Copy link
Contributor

Started working on this and I have some questions here. Specifically, since GetContext() can be called on any thread, I don't really how to handle this specific error. Since it is not running on the Node thread, any Error-creating methods wont work (there is no napi_env) ...

inline ThreadSafeFunction::ConvertibleContext
ThreadSafeFunction::GetContext() const {
  void* context;
  
  napi_status status = napi_get_threadsafe_function_context(*_tsfn, &context);
  NAPI_FATAL_IF_FAILED(status, "ThreadSafeFunction::GetContext", "napi_get_threadsafe_function_context");
  
  return ConvertibleContext({ context });
}

This works, but as a fatal error, will end the process, and does not allow a way for the caller to catch this error -- with NAPI_DISABLE_CPP_EXCEPTIONS I cannot surround my GetContext() call with try/catch ... so I don't know how to continue.

Any suggestions?

@legendecas
Copy link
Member Author

legendecas commented Oct 31, 2019

I think aborting would be just fine. Since we don't expect any error on this method. Neither do we have any recover solution on the error situation.

KevinEady added a commit to KevinEady/node-addon-api that referenced this issue Oct 31, 2019
@gabrielschulhof
Copy link
Contributor

Looking at the implementation, napi_get_threadsafe_function_context() will only fail if one of the parameters passed in is NULL. So, since both parameters are under our control, it should never fail – unless, in the future, we introduce some new failure mode, in which case the abort should be perfect.

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

Successfully merging a pull request may close this issue.

3 participants