Search code examples
node.jsexpressbotsmessengersuperagent

Messenger Bot "sleep mode" getaddrinfo


I got a bot made in nodejs (expressjs) and hosted on my private VPS, I encounter a bug with HTTP request made with superagent lib. When there is a long period of inactivity, the nodejs server is like in "sleep mode", and the first request is always an error caught in my try/catch, the error look like this : enter image description here

I got another bot hosted on heroku but I don't have this error, it seems it's maybe my VPS/Apache proxy ?

After the first request, when I made a new one, it works as expected. It's like my server is in "sleep mode" and the first request tell him to wake up.

Thanks for your answers.


Solution

  • This is a normal behaviour for NodeJS applications. To prevent the server for shutting down your application after inactivity, you can do a ping request every x minutes (or seconds) to keep your bot alive.

    You can also use the .setTimeout() function.

    server.setTimeout(10*60*1000);
    

    Source: Nodejs and express server closes connection after 2 minutes