1

I am having a problem deploying my web app on Heroku. I already set the database on MongoDB Atlas. The database is working when I am running "node app.js" locally. After deploying my project on Heroku I got an Application error and when I run "heroku logs --tail" I got the error below ;

2020-03-07T19:53:58.266177+00:00 heroku[web.1]: Idling
2020-03-07T19:53:58.269259+00:00 heroku[web.1]: State changed from up to down
2020-03-07T19:53:59.799552+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2020-03-07T19:53:59.987938+00:00 heroku[web.1]: Process exited with status 143
2020-03-07T20:02:06.452667+00:00 heroku[web.1]: Unidling
2020-03-07T20:02:06.468513+00:00 heroku[web.1]: State changed from down to starting
2020-03-07T20:02:09.189010+00:00 heroku[web.1]: Starting process with command `node app.js`
2020-03-07T20:02:11.522634+00:00 app[web.1]: Server started on port 3000
2020-03-07T20:02:12.987457+00:00 heroku[web.1]: State changed from starting to up
2020-03-07T20:02:41.597213+00:00 app[web.1]: (node:4) UnhandledPromiseRejectionWarning: MongooseServerSelectionError: connection <monitor> to 35.172.242.193:27017 closed
2020-03-07T20:02:41.597235+00:00 app[web.1]: at new MongooseServerSelectionError (/app/node_modules/mongoose/lib/error/serverSelection.js:22:11)
2020-03-07T20:02:41.597236+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:808:32)
2020-03-07T20:02:41.597237+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:333:15)
2020-03-07T20:02:41.597237+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:14:10)
2020-03-07T20:02:41.597238+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:955:30)
2020-03-07T20:02:41.597238+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
2020-03-07T20:02:41.597239+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:811:32)
2020-03-07T20:02:41.597239+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:723:14)
2020-03-07T20:02:41.597239+00:00 app[web.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)
2020-03-07T20:02:41.597240+00:00 app[web.1]: at internal/main/run_main_module.js:17:11
2020-03-07T20:02:41.597341+00:00 app[web.1]: (node:4) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
2020-03-07T20:02:41.597434+00:00 app[web.1]: (node:4) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
2020-03-07T20:02:43.524590+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/" host=protected-coast-44428.herokuapp.com request_id=9a7b66e6-1280-4d0c-b13d-10548513bc70 fwd="159.146.14.191" dyno=web.1 connect=0ms service=30000ms status=503 bytes=0 protocol=https
2020-03-07T20:03:17.579588+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/favicon.ico" host=protected-coast-44428.herokuapp.com request_id=3d335054-de74-4abb-982c-135988919edb fwd="159.146.14.191" dyno=web.1 connect=1ms service=30000ms status=503 bytes=0 protocol=https

Please note that I don't have any favicon.ico in my project. I had it in my previous project and I deleted that project on Heroku because of this error, and I don't know why I am still getting favicon on my error.

I made sure that I wrote the right user name and password in app.js and I added my IP in the whitelist as well.

mongoose.connect("mongodb+srv://username:password*@cluster0-h6uqp.mongodb.net/todolistDB",
{ useNewUrlParser: true, useUnifiedTopology: true });
Eliftch
  • 218
  • 1
  • 4
  • 13
  • Does this answer your question? [How to have more then 30sec response timeout in heroku](https://stackoverflow.com/questions/69497229/how-to-have-more-then-30sec-response-timeout-in-heroku) – ggorlen Jan 30 '23 at 23:34

2 Answers2

1

I solved the issue by changing networking access to 'ALLOW ACCESS FROM ANYWHERE' on MongoDB. Here

Eliftch
  • 218
  • 1
  • 4
  • 13
0

Heroku on free plan, closes the dynos after 30 minutes of inactivity. More on this here.

Going by your logs, it looks like the mongo connection was closed after 30 minutes the app was started. Looks like you are affected by this.

The error though seems to be caused by no handling of mongo connection closing in the app.

tbking
  • 8,796
  • 2
  • 20
  • 33
  • Thank you for answering. current dynos status: **Free dyno hours quota remaining this month: 550h 0m (100%)** So what do you recommend me to do about the error caused by no handling of mongo connection? – Eliftch Mar 08 '20 at 10:28