Segmentation fault (core dumped) when listen to https using example WorkerThreads.js
Opened this issue · 0 comments
snowinszu commented
code like this:
if (isMainThread) {
/* The acceptorApp only listens, but must be SSL if worker apps are SSL and likewise opposite */
const acceptorApp = uWS.SSLApp({
key_file_name: 'misc/key.pem',
cert_file_name: 'misc/cert.pem',
passphrase: '1234'
}).listen(port, (token) => {
if (token) {
console.log('Listening to port ' + port + ' from thread ' + threadId + ' as main acceptor');
} else {
console.log('Failed to listen to port ' + port + ' from thread ' + threadId);
}
});
/* 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 */
new Worker(__filename).on("message", (workerAppDescriptor) => {
acceptorApp.addChildAppDescriptor(workerAppDescriptor);
});
});
/* I guess main thread joins by default? */
} else {
/* Here we are inside a worker thread */
const app = uWS.SSLApp({
key_file_name: 'misc/key.pem',
cert_file_name: 'misc/cert.pem',
passphrase: '1234'
}).get('/*', (res, req) => {
res.end('Hello Worker!');
}).listen(4000, (token) => {
if (token) {
console.log('Listening to port ' + 4000 + ' from thread ' + threadId);
} else {
console.log('Failed to listen to port ' + 4000 + ' from thread ' + threadId);
}
});
/* The worker sends back its descriptor to the main acceptor */
parentPort.postMessage(app.getDescriptor());
}
Testing on ubuntu 24.04