metacom
metacom copied to clipboard
Listening port undefined on worker 0
Describe the bug Metacom Server should start only inside worker. If you try to start Metacom Server in a process, it starts on port undefined.
To Reproduce Test:
metatests.test('Server class testing', (test) => {
const config = {
host: '::',
balancer: 8000,
protocol: 'http',
ports: [8000],
nagle: true,
timeouts: {
bind: 2000,
start: 30000,
stop: 5000,
request: 5000,
watch: 1000,
},
queue: {
concurrency: 1000,
size: 2000,
timeout: 3000,
},
workers: {
pool: 2,
},
};
const application = {
console: {
log: (args) => {
console.log(args);
},
error: (args) => {
console.error(args);
},
info: (args) => {
console.info(args);
},
},
};
const server = new Server(config, application);
test.strictSame(typeof server, 'object');
test.end();
});
Expected behavior Throw an Error.
Desktop (please complete the following information):
- OS: Arch Linux 5.12 Kernel
- Node.js version 14
Additional context
Simple fix:
server.js
bind() {
if (threadId === 0) {
throw new Error('Server must start in worker');
}
...
}
Please make branch with this test and WIP (work in progress PR), I decided to implement thread0 metacom support without balance.
I created a pull request with 2 tests.
First test: single process case with threadId === 0
, which is mainThreadId
Second test: case with 3 workers no balancer and 2 ports. Same problem occurs. Server is starting in worker 3 with port undefined
.