express-metrics icon indicating copy to clipboard operation
express-metrics copied to clipboard

Server cannot handle cluster worker unhandled exception

Open lyonlai opened this issue 6 years ago • 3 comments

Hi there,

Love the library as it's quite simple to use. Got question about the communication between worker & master

At the moment the communication is from worker reporting to the master via worker's process.send

and the server is listening on 'message' event. But when a process has gone south and new worker spins up. the server will not get the new message as there's no listening in the fork event on the cluster.

I'm hitting this problem right now. and I think there are two ways to solve it.

  1. make the server.cluster.proxy to listen on 'fork' event and make it pick up new workers.

  2. use cluster.worker.send in the client and process.on('message') on the server proxy.

feels to me the second way is more natural. Thought?

I can quickly submit a PR if you want. Let me know if you want to think more about it.

Cheers

lyonlai avatar Sep 02 '17 01:09 lyonlai

nvm what I said about No.2, after some reading I'll just put an event handler on fork so that server can handle newly spin up workers.

lyonlai avatar Sep 02 '17 11:09 lyonlai

Thanks for the feedback!

As you said, I'll go for option 1. I'm totally open to contributions, so I encourage you to send a PR. It'd be very nice.

To be honest, currently I don't use this library. I believe a server should not collect, aggregate and expose it own metrics. Said that, under some circumstances express-metrics is still useful.

I'll take a look to the process messaging when a worker disconnects and a new one is forked.

dgaubert avatar Sep 03 '17 13:09 dgaubert

Well as long as the stats port is different and not open to public. I'm ok as I'm at the moment try to come up with some stats quick to verify my idea. It's quite useful. Also the stated part is cool too.

Btw what do you use now?

lyonlai avatar Sep 03 '17 20:09 lyonlai