I’m trying to troubleshoot one of our pubsub listeners running in a docker container on a aws instance randomly shutting off after few days.
It is written in nodejs using this sdk which is
I observed there is no spike in cpu or memory. The container is running but pubsub connection closes and it is after random set of days.
Following is the snippet which I have a re-connect mechanism. I see the service close log message but it never gets to the re-connect.
Appreciate any suggestions to troubleshoot.
function connect(ws: WebSocket) {
ws.on('error', (error) => console.log(error));
ws.on('open', () =>
console.log(
'******** Pubsub listening to messages! ********* ',
new Date().toISOString()
)
);
ws.on('close', (e) => {
console.log(
'Service connection is CLOSED. Reconnect will be attempted in 5s.',
e
);
setTimeout(function () {
connect(ws);
}, 5000);
});
ws.on('message', async (data) => {
console.log('Message received: %s %s', data, new Date().toISOString());
..
..
..
..
});
}