mongoose icon indicating copy to clipboard operation
mongoose copied to clipboard

Weird npm error connecting elastic beanstalk node app to a Mongo 4.0 Cloud Atlas cluster

Open upugo-dev opened this issue 7 years ago • 5 comments

Node 8.11.1 running on Amazon linux eb container Mongoose 5.6.1 [email protected]

What is the current behavior? Can connect with no problems to a Mongo 3.6 M10 cluster using the 2.2 connection string format:

mongodb://<username>:<password>@xxx-cluster-shard-00-00-xxx.mongodb.net:12345,xxxx-cluster-shard-00-01-xxx.mongodb.net:12345,development-cluster-shard-00-02-xxx.mongodb.net:12345/mydb?ssl=true&replicaSet=xxx-cluster-shard-0&authSource=admin&retryWrites=true&w=majority

Connecting to a Mongo 4.0 M20 cluster, on the same Atlas account, throws a really weird error;

┌──────────────────────────────────────────────────┐
│ npm update check failed │
│ Try running with sudo or get access │
│ to the local update config store via │
│ sudo chown -R $USER:$(id -gn $USER) /tmp/.config │
└──────────────────────────────────────────────────┘

Just to clarify, the only change I am making is changing the connection string (which I pass to mongo via and env var). I have tried the 3.0 and 2.2 connection formats, no luck. Any ideas what is going on here? Cheers

upugo-dev avatar Jun 27 '19 10:06 upugo-dev

That error message isn't from mongoose... Does your container run npm install when it restarts?

vkarpov15 avatar Jun 30 '19 19:06 vkarpov15

Yes it does, and yes it was (sort of). I found out that someone had suppressed logging uncaught rejections to console. I turned that back on, and found out that the connection string was invalid (mongoose throwing as expecting), but the npm update check failed was also throwing along with it. Strange.

Correcting the connection string, after an hour or so of fiddling around, has resolved this issue, but it's still strange to me that an invalid connection string could be causing this npm error message to appear.

upugo-dev avatar Jul 01 '19 15:07 upugo-dev

There's a lot of unrelated explanations on SO for this issue. But since Mongoose doesn't run npm, I think we can rule out Mongoose as the cause.

vkarpov15 avatar Jul 03 '19 18:07 vkarpov15

I know, I read pretty much every thread on SO in a panic when I was trying to fix this issue on our deployed applications... 😲

In short:

Good string -> no errors Bad string -> throw mongoose connection error, but also npm update check failed

^^^ changing only this variable to get npm update check failed message

The npm update check failed is not a Node run-time exception/rejection, since it was logging to console even though my code had (it wasn't me 🙄 ) inhibited process.on(uncaughtexceptions) from logging to console.

OK, Mongoose doesn't call run npm, but it does call mongo native driver and a bunch of other stuff on the npm framework.

Is it possible that by pointing mongoose at a host db that the client mongo driver is unable to support a connection to, could cause npm to go "hey, I need to update mongo in order to access this db", and the npm update check failed message appears because of AWS permissions errors? This would be more inline with the more commonly seen form of the npm update check failed error, where people are seeing it during deployments/updates on cloud-managed servers without root permission.

Something must be calling npm

upugo-dev avatar Jul 03 '19 23:07 upugo-dev

No, that is not possible to the best of my knowledge. npm only runs when you explicitly run it on the command line, npm does not run when you require() a module or connect to MongoDB. Unless, of course, you've configured Node.js to run npm update on require(), but that doesn't happen by default.

vkarpov15 avatar Jul 08 '19 18:07 vkarpov15