- Notifications
You must be signed in to change notification settings - Fork611
Does not work with clustering.#304
-
When a child binds its port the other children fail constcluster=require("cluster");constnumCPUs=require("os").cpus().length;if(cluster.isMaster){// Fork workers.for(leti=0;i<numCPUs;i++){cluster.fork();}console.log("Master starting "+newDate().toISOString());cluster.on("exit",()=>{process.exit(1);});}else{// worker taskrequire("./server");} |
BetaWas this translation helpful?Give feedback.
All reactions
From the path in your stack trace, it seems you're using macOS.
Your example code omitstwo important lines:
/* This example spawns two worker threads, each with their own * server listening to the same port (Linux feature). */
Note the "Linux feature" parenthetical remark.
@alexhultman can confirm, but I believeSO_REUSEPORT
on Linuxuniquely supports (as of 3.9) TCP and UDP sockets, whereasSO_REUSEPORT
on macOS only supports UDP sockets. macOS does not know what to do with two threads that request to be bound to the same TCP port.
Replies: 4 comments 1 reply
-
It does work with clustering, but focus lies on WorkerThreads:https://github.com/uNetworking/uWebSockets.js/blob/master/examples/WorkerThreads.js |
BetaWas this translation helpful?Give feedback.
All reactions
-
This does not work because acceptorApp.addChildAppDescriptor is not defined. |
BetaWas this translation helpful?Give feedback.
All reactions
-
Thanks for your help, ill give it a shot |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
It seems to not work either. Any insight?@alexhultman constuWS=require('uWebSockets.js');constport=9001;const{ Worker, isMainThread, threadId}=require('worker_threads');constos=require('os');if(isMainThread){/* Main thread loops over all CPUs *//* In this case we only spawn two (hardcoded) *//*os.cpus()*/[0,1].forEach(()=>{/* Spawn a new thread running this source file */newWorker(__filename);});/* I guess main thread joins by default? */}else{/* Here we are inside a worker thread */constapp=uWS.App({}).get('/*',(res,req)=>{res.end('Hello Worker!');}).listen(port,(token)=>{if(token){console.log('Listening to port '+port+' from thread '+threadId);}else{console.log('Failed to listen to port '+port+' from thread '+threadId);}});} $ node worker-threads.jsListening to port 9001 from thread 1Failed to listen to port 9001 from thread 2uv loop at [0x700008fd0af8] has open handles:[0x10a00a6d0] prepare (active)Close callback: 0x128008000Data: 0x10a00a570(First field): 0x10a00a7d0[0x10a00a750] check (active)Close callback: 0x0Data: 0x10a00a570(First field): 0x10a00a7d0[0x10a00a8a0] timer (active)Close callback: 0x0Data: 0x10a00a7d0[0x10a00bdc0] async (active)Close callback: 0x0Data: 0x10a00bcf0uv loop at [0x700008fd0af8] has 4 open handlesin totalnode[34486]: ../src/debug_utils.cc:322:void node::CheckedUvLoopClose(uv_loop_t*): Assertion`0&&"uv_loop_close() while having open handles"' failed. 1: 0x101224565 node::Abort() (.cold.1) [/Users/jtwhissel/.nvm/versions/node/v14.1.0/bin/node] 2: 0x10009d6d9 node::Abort() [/Users/jtwhissel/.nvm/versions/node/v14.1.0/bin/node] 3: 0x10009d541 node::Assert(node::AssertionInfo const&) [/Users/jtwhissel/.nvm/versions/node/v14.1.0/bin/node] 4: 0x10002d18e node::CheckedUvLoopClose(uv_loop_s*) [/Users/jtwhissel/.nvm/versions/node/v14.1.0/bin/node] 5: 0x100132976 node::worker::WorkerThreadData::~WorkerThreadData() [/Users/jtwhissel/.nvm/versions/node/v14.1.0/bin/node] 6: 0x10012f451 node::worker::Worker::Run() [/Users/jtwhissel/.nvm/versions/node/v14.1.0/bin/node] 7: 0x100132af9 node::worker::Worker::StartThread(v8::FunctionCallbackInfo<v8::Value> const&)::$_3::__invoke(void*) [/Users/jtwhissel/.nvm/versions/node/v14.1.0/bin/node] 8: 0x7fff6f023109 _pthread_start [/usr/lib/system/libsystem_pthread.dylib] 9: 0x7fff6f01eb8b thread_start [/usr/lib/system/libsystem_pthread.dylib]Abort trap: 6 |
BetaWas this translation helpful?Give feedback.
All reactions
-
From the path in your stack trace, it seems you're using macOS. Your example code omitstwo important lines: /* This example spawns two worker threads, each with their own * server listening to the same port (Linux feature). */ Note the "Linux feature" parenthetical remark. @alexhultman can confirm, but I believe |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
This discussion was converted from issue #304 on December 09, 2020 05:28.