uNetworking / uWebSockets.js

μWebSockets for Node.js back-ends :metal:
Apache License 2.0
8.09k stars 577 forks source link

Windows worker threads cleanup #668

Closed e3dio closed 2 years ago

e3dio commented 2 years ago

Something on Windows (11, node 17) does not clean up the addon properly I think, when you exit the last remaining worker thread that imported uWS.js it crashes the process with code 3221225477 'invalid access', this does not happen on Linux. This is not the worst thing because closing the last worker thread usually means you are done with the process, but clean exit would be good

const {Worker,isMainThread}=require('worker_threads')
if(isMainThread){
    new Worker(__filename).on('exit',code=>console.log('worker thread (from main) exited',code))
    process.on('exit',code=>console.log('main thread exited',code))
}else{
    //require('uWebSockets.js')
    setTimeout(()=>console.log('done, worker exiting'),1000)
    process.on('exit',code=>console.log('worker thread (inside) exited',code))
}

Uncomment require('uWebSockets.js') and get process crash on thread exit, worker thread (inside) exited gets logged but worker thread (from main) exited and main thread exited don't get logged

https://nodejs.org/api/addons.html#worker-support

e3dio commented 2 years ago

I am not using this on Windows am using Linux, most should be using Linux, closing as not relevant edge case