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

[v0.81.0] worker_threads doesn't work with node.js in nwjs #8082

Closed
2 tasks done
Matt-Maerz opened this issue Jun 29, 2023 · 14 comments
Closed
2 tasks done

[v0.81.0] worker_threads doesn't work with node.js in nwjs #8082

Matt-Maerz opened this issue Jun 29, 2023 · 14 comments
Assignees

Comments

@Matt-Maerz
Copy link

Matt-Maerz commented Jun 29, 2023

Issue Type

  • Bug Report
  • Successfully reproduced against the latest version of NW.js?

Current/Missing Behavior

Same like: #7114

With version 0.81.0 the app crashes without any errors. It started with version v0.69.1, see below
I have used the attached example, just remove the *.txt extension from the files

It is exactly the example from here #7114 (comment)
An HTML and a Server.js is loaded. In the Server.js a Worker is called.
The Worker writes a txt file with Hello World

index.html.txt
package.json.txt

{
    "additional_trust_anchors": [],
    "app_name": "TestWorker",
    "chromium-args": "--enable-node-worker",
    "js-flags": "--enable-node-worker",
    "main": "index.html",
    "name": "testworker",
    "node-main": "Server.js",
    "node-remote": [],
    "nodejs": true,
    "single-instance": false,
    "version": "0.0.1",
    "webexe_settings": {
        "blacklist": "",
        "custom_script": "",
        "download_dir": "",
        "force_download": false,
        "linux-x32": false,
        "linux-x64": false,
        "mac-x64": false,
        "nw_compression_level": 0,
        "nw_version": "0.77.0",
        "output_pattern": "",
        "sdk_build": true,
        "uncompressed_folder": true,
        "whitelist": "",
        "windows-x32": false,
        "windows-x64": true
    },
    "webkit": {
        "double_tap_to_zoom_enabled": false,
        "plugin": false
    },
    "window": {
        "always_on_top": false,
        "as_desktop": true,
        "frame": true,
        "fullscreen": false,
        "id": "TestwebWorker",
        "kiosk": false,
        "kiosk_emulation": false,
        "position": "center",
        "resizable": true,
        "show": true,
        "show_in_taskbar": true,
        "title": "TestwebWorker",
        "transparent": false,
        "visible": true,
        "visible_on_all_workspaces": true
    }
}

Server.js.txt

const wt = require('node:worker_threads');
 try{
	setTimeout(function(){
		let w = new wt.Worker("./workerFile.js");
	}, 500);
 }catch(err){
	console.log(err);
 }

workerFile.js.txt

console.log("START Nodejs WORKER");
const fs=require('fs');
fs.writeFileSync('output.txt', "hello world");

Additional Info

  • Operating System: Win 11 v.22H2
  • NW.js Versions: Here a list which versions work and where you can find the crash. It started with version v0.69.1
    0.81.0 ⛔ (Crash)
    0.80.0 ⛔
    0.79.1 ⛔
    0.79.0 ⛔
    0.78.1 ⛔
    0.78.0 ⛔
    0.77.0 ⛔
    0.76.1 ⛔
    0.76.0 ⛔
    0.75.0 ⛔
    0.74.0 ⛔
    0.73.0 ⛔
    0.72.0 ⛔
    0.71.0 ⛔
    0.70.1 ⛔
    0.70.0 ⛔
    0.69.1 ⛔
    0.69.0 ✅
    0.68.1 ✅
    0.68.0 ✅
    0.67.0 ✅
    0.66.0 ✅
    0.65.1 ✅ (no Crash)
@qsenn35
Copy link

qsenn35 commented Jun 30, 2023

Hey there, just chiming in to say I ran into the same issue.

Web Workers did work for me though, so if you need to run another thread desperately you can do that. I'm not sure of the performance differences but that was the only way I could open a new thread.

@Matt-Maerz
Copy link
Author

Matt-Maerz commented Jun 30, 2023

Hey, thanks for your reply.

Maybe I'm being a little silly but can you share a little more of the solution.
Am I doing something wrong in the above example?
Do you have a workaround or another approach?

Because with version 0.65.1 everything worked and with the latest version it doesn't work anymore.
So something must have changed fundamentally in the structure of nwjs, right?

Thanks already for your time.

@Matt-Maerz
Copy link
Author

Hello @helloitsian,
sorry to bother you again.
I tried Web Worker: https://github.com/developit/web-worker

I change the Code:

const WebWorker = require('web-worker');
try{
	setTimeout(function(){
		let w = new WebWorker("./workerFile.js",{ type: 'module' });
	}, 500);
}catch(err){
	console.log(err);
}

But unfortunately this does not result in any change.
It crashes without error message
Do you have any other tips?

@sysrage
Copy link

sysrage commented Jul 7, 2023

I believe @helloitsian was suggesting you use web workers that are already built-in to the browser context. You would not be able to launch them via node-main. You would launch them via main.

@Matt-Maerz
Copy link
Author

Thanks for the clarification. I have then misunderstood.
Web Worker in the browser works fine.
The problem is only in the nodejs context

@Matt-Maerz Matt-Maerz changed the title worker_threads doesn't work with node.js in nwjs worker_threads doesn't work with node.js in nwjs (v.0.78.1) Aug 14, 2023
@Matt-Maerz Matt-Maerz changed the title worker_threads doesn't work with node.js in nwjs (v.0.78.1) worker_threads doesn't work with node.js in nwjs (v0.78.1) Aug 14, 2023
@Matt-Maerz Matt-Maerz changed the title worker_threads doesn't work with node.js in nwjs (v0.78.1) worker_threads doesn't work with node.js in nwjs (v0.79.0) Aug 19, 2023
@Matt-Maerz Matt-Maerz changed the title worker_threads doesn't work with node.js in nwjs (v0.79.0) [v0.79.0] worker_threads doesn't work with node.js in nwjs Aug 19, 2023
@rogerwang rogerwang self-assigned this Aug 20, 2023
@rogerwang
Copy link
Member

It works for me with 0.79.0 on Linux.

@Matt-Maerz
Copy link
Author

It works for me with 0.79.0 on Linux.

Hey, Thanks for your reply and the test.
Just to be sure again, no offense intended, have you tested NodeJS's worker_threads?
https://nodejs.org/api/worker_threads.html

I have tested it on WIN 10 and 11 unfortunately with a crash
I will then test it right away on Steamdeck's Linux.

@sysrage
Copy link

sysrage commented Aug 21, 2023

I'm also seeing this crash in Windows 10 with 0.78.1 and 0.79.0. Min. repro:

package.json

{
  "name": "test",
  "main": "main.html",
  "node-main": "node-main.js",
  "chromium-args": "--enable-logging=stderr"
}

main.html

Hello World.

node-main.js

const wt = require('node:worker_threads');
 try {
  console.log('starting worker');
  let w = new wt.Worker("./workerFile.js");
 } catch (err) {
	console.log(err);
 }

workerFile.js

console.log("in Node.js worker");
const fs=require('fs');
fs.writeFileSync('output.txt', "hello world");

The "starting worker" log is shown, then NW.js crashes with no errors.

EDIT: The above code works without any issues in macOS.

@rogerwang
Copy link
Member

rogerwang commented Aug 21, 2023 via email

@Matt-Maerz
Copy link
Author

Matt-Maerz commented Aug 21, 2023

I was testing with the code you provided in the first post.

Ok, thank you very much.

That means it is even more difficult to create a fix for this.

Is there any crash report in win10/win11 from nwjs where you can still possibly see the error?
Or that we can provide to you?

Or are there noticeable differences/hints if you look at the version differences at
0.69.1 ⛔
0.69.0 ✅

@Matt-Maerz Matt-Maerz changed the title [v0.79.0] worker_threads doesn't work with node.js in nwjs [v0.79.1] worker_threads doesn't work with node.js in nwjs Aug 24, 2023
@Matt-Maerz
Copy link
Author

@rogerwang
do you have a way to recreate the error on Windows?

If you need any information, let me know.
Whatever you need.

My reason is the WebGPU support from chrome 113 (https://developer.chrome.com/blog/webgpu-release/)
This is an important step for many frameworks or gameengines in HTML5.

@Matt-Maerz Matt-Maerz changed the title [v0.79.1] worker_threads doesn't work with node.js in nwjs [v0.81.0] worker_threads doesn't work with node.js in nwjs Oct 22, 2023
@rogerwang
Copy link
Member

This is fixed in git and will be available in the next nightly build.

@rogerwang
Copy link
Member

@Matt-Maerz
Copy link
Author

I tested it and it works again!
Thanks a Lot. Great Work.

@CosmoMyzrailGorynych CosmoMyzrailGorynych moved this to Blocked in Overlook Dec 21, 2023
@CosmoMyzrailGorynych CosmoMyzrailGorynych moved this from Blocked / Upstream bugs to Done in Overlook May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants