Running a node js (v 18.13.0) app under Heroku (Heroku-22 stack) using express and mongoose to access a MongoDB Atlas cluster. This app was working until I migrated it from mongoose v6.8.4 (MongoDB driver v4) up to mongoose v8.16.1 (MongoDB driver v6). After this update, the app fails to connect to the database, with the error:
Client network socket disconnected before secure TLS connection was established
Some background: I made updates to the app for breaking changes between mongoose versions. Successfully tested the app with the latest mongoose package / MongoDB driver against a local MongoDB 8.0 community server. However it fails when running under Heroku while trying to connect to the Atlas db. Note that SSL certificates are managed by Heroku. I also see that in the latest MongoDB driver release notes, TLS certificate authority and certificate-key files are now read asynchronously (donāt know if this factors into the problem).
I finally reverted my app to use the mongoose v6.8.4 / MongoDB driver v4 package (while keeping the migration code changes I had made to move up to the latest driver), and viola, the app is now working again under Heroku and my Atlas MongoDB cluster.
So, it seems that some difference in the latest drivers behavior is causing a break in how my app or Heroku or Atlas is dealing with the connect. Any ideas?
This is not an IP white list problem. Also, my mongoose connect code is rather vanilla:
Hereās some new information. I tried some versions of mongoose / MongoDB driver that are earlier than the latest 6.17.0 driver, but later than my v4 driver. Mongoose 8.12 / MongoDB driver 6.14 still has the problem. But, mongoose 7.6.3 / MongoDB 5.9 works! This strongly points to some change introduced in the MongoDB v6 drivers that is playing a role in this failure. Not to say there is necessarily a bug in the driver. It could just be a valid change that is interacting with the way either Heroku is managing SSL/TLS and/or my node js code.
Anyone familiar with changes introduced in the MongoDB v6 drivers regarding connection logic? This would be very helpful in gaining insight into whatās causing this issue. In the meantime, I am not blocked in my development, as using the MongoDB v5 driver gives me some more runway before having to move to a newer driver.
Just to clarify, our MongoDB Atlas cluster has already been fully migrated to version 8.
The MongoDB Node.js driver 5.9 is not fully compatible with MongoDB 8 (see: Compatibility - Node.js Driver v6.17 - MongoDB Docs), but since weāre not using any of the new features, it has been working for us so far.
We tested downgrading the versions, and everything seems to be working, so we suspect the issue might be related to Mongoose, the MongoDB Node.js driver, or a new configuration introduced recently.
Hey David, as the Product Manager for our JavaScript Developer Experience Iām happy to jump in here - though unfortunately I donāt have a smoking gun ⦠yet.
Client network socket disconnected before secure TLS connection was established
This error isnāt specifically a driver issue, mongoose issue or potentially even Node issue as it appears to be a TLS issue. This doesnāt mean there isnāt a breakdown somewhere in the stack that is triggered by upgrading the MongoDB Node.js driver, so the first step would be to just āsee what we can seeā.
Assuming you have a workload that is working properly 100% of the time with the v4 Node.js driver, and ābreaksā 100% of the time with the v5+ Node.js driver could someone test this by running their workload using NODE_DEBUG=tls node ... to enable debug information printing for the net:tls module?
Weāre hoping this helps surface whatās contributing to this issue.