Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Does not work with clustering.#304

Answeredbyadelyte-chris
Phara0h asked this question inQ&A
Discussion options

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");}
You must be logged in to vote

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

Comment options

It does work with clustering, but focus lies on WorkerThreads:https://github.com/uNetworking/uWebSockets.js/blob/master/examples/WorkerThreads.js

You must be logged in to vote
1 reply
@johnsonfash
Comment options

This does not work because acceptorApp.addChildAppDescriptor is not defined.

Comment options

It does work with clustering, but focus lies on WorkerThreads:https://github.com/uNetworking/uWebSockets.js/blob/master/examples/WorkerThreads.js

Thanks for your help, ill give it a shot

You must be logged in to vote
0 replies
Comment options

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
You must be logged in to vote
0 replies
Comment options

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.

You must be logged in to vote
0 replies
Answer selected
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
3 participants
@Phara0h@adelyte-chris@johnsonfash
Converted from issue

This discussion was converted from issue #304 on December 09, 2020 05:28.


[8]ページ先頭

©2009-2025 Movatter.jp