Event triggered when restart occurs?

Hi -

I have a background worker that uses a streaming API. I am just simply using nodejs fetch and then using response.body.getReader() to accomplish this.

It works great - but I have recently received feedback that the stream never appears to properly disconnect.

This is concerning, as I did set up a nodeCleanup behavior using the node-cleanup npm package node-cleanup - npm, which should iterate through any open readers and call reader.close()

HOWEVER - reader.close() is an async call, and nodeCleanup’s function is called synchronously… so possibly that is the problem I think

I know that with render’s zero-downtime it’s a bit mysterious when one process ends and another begins - but is there some other option within render to have an old process call some methods (preferrably async) when the process is ending? Perhaps some event fired within node I can attach to?

Thanks in advance :pray:

Hi Billy,

Yes, you can catch the SIGTERM Render sends, then take some action based on that. More information on that is here https://docs.render.com/deploys#zero-downtime-deploys

One thing we have seen is that if you start your server with npm ... or yarn ... the SIGTERMs seem to get intercepted and never make it to your application. If you start your service with node ... you should be able to detect the SIGTERM.

Regards,

Matt

1 Like

Aha - I was using node-cleanup and it didn’t seem to be working, I did not know starting with yarn was possibly an issue. Thank you for the information, not so mysterious after all!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.