Sitelet https://web.archive.org/web/20220405131742/https://github.com/nodejs/node-addon-api/issues/784
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

Thread-safe Functions weird issue on windows, not on linux or mac #784

Closed
deshan opened this issue Aug 5, 2020 · 3 comments
Closed

Thread-safe Functions weird issue on windows, not on linux or mac #784

deshan opened this issue Aug 5, 2020 · 3 comments
Labels

Comments

@deshan
Copy link

@deshan deshan commented Aug 5, 2020 •

Hi,
I'm trying a simple Thread-safe Function example,
https://napi.inspiredware.com/special-topics/thread-safe-functions.html
This example works as expected in mac and Linux platforms. But not in windows.

auto callback = [](Napi::Env env, Napi::Function jsCallback, int *data) {
    jsCallback.Call({Napi::Number::New(env, *data)});
  };

App config

Electron app with React and webpack.

Problem

jsCallback.Call
not gets called sometimes.

Works ok on windows when

  1. Run with node (eg : node app.js)
  2. Run inside Electron app without react

Does not work on windows when

Run inside a react js code in an Electron app

I'm using native-ext-loader (https://www.npmjs.com/package/native-ext-loader) to load the native node module in webpack rules.

     rules :[ {
        test: /\.node$/,
        loader: "native-ext-loader",
        options: {
          rewritePath: path.resolve(__dirname, "../build/Release")
        }
      },
@deshan deshan changed the title Thread-safe Functions wired issue on windows, not on linux or mac Thread-safe Functions weird issue on windows, not on linux or mac Aug 5, 2020
@abram
Copy link

@abram abram commented Aug 8, 2020

I'm also running into this issue with an Electron (version 9.1.2) app on Windows. I have a C++ module running some async processes. My JS code registers a callback function so it can be notified when the native code state changes. On the C++ side this is done with a ThreadSafeFunction. I haven't had any problems in macOS, but the JS callback is unreliable on Windows. Incidentally I am also using React (and Redux).

The behavior I'm seeing is similar to #622. It seems that ThreadSafeFunction calls sometimes queue up and don't get processed for a long time. Eventually, and seemingly at random, a new ThreadSafeFunction call will break the logjam, and all previously queued TheadSafeFunction calls will be processed.

@mhdawson
Copy link
Member

@mhdawson mhdawson commented Sep 22, 2020

The challenge on the N-API team side is that seems to be related to react and I don't think any of our team members are that familiar with it. Opening an issue in the electron or react repos might make sense to see if anybody has come across the same issue/resolved in those repos.

@github-actions
Copy link

@github-actions github-actions bot commented Dec 22, 2020

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.

@github-actions github-actions bot added the stale label Dec 22, 2020
@github-actions github-actions bot closed this Jan 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants