MongoDB Error: "MongoServerClosedError: Server is closed"
Project id: 8b67ba4d-ba67-4f38-97ef-8caab4e245fe
Hi folks, my express server has trouble connecting to my mongo service on startup. It was functioning with a mongodb plugin until a couple weeks ago. I thought maybe I'll try switching to a mongodb image-based service in case it magically starts working. But the exact same error. WOuld appreciate some insight, thank you!
55 Replies
Project ID:
8b67ba4d-ba67-4f38-97ef-8caab4e245fe
mongoose?
nope, nodejs mongo driver
repo:
GitHub
GitHub - BenIsenstein/notion_integration_1
Contribute to BenIsenstein/notion_integration_1 development by creating an account on GitHub.
looking
Thanks Brody 🙂
can you please try setting this https://mongodb.github.io/node-mongodb-native/4.11/interfaces/MongoOptions.html#connectTimeoutMS to a higher value like 10000?
SUre, it's a part of the Client options object?
looks to be, yeah
pushed to my repo, let's monitor the deployment
you tell me what happens, i cant monitor anything lol
lol I figured I was giving you implicit consent to observe my project infra
dont work for railway so i cant see anything
Oh I thought you worked for them! What's your relation to them/how did you end up being a conductor?
i help so they gave me cool role
sweety
alright still a failed health check after 10s
what do the deployment logs look like?
that doesnt look like there was even a connection attempt?
So I'm trying to synchronously fetch the Google OAuth refresh tokens before the connection is established
Kay let me dig to the. bottom
keep me updated
If you want to look in my repo the file is /repositories/mongo
Some background
I run many one-time mongo operations inside of a wrapper function called "withConnectAndClose()"
looks good to me
my entry file for the project starts by running a function "initGoogleApi()"
little tip, wrap your code in triple back ticks
That initGoogleApi() function is warpped with withConnectAndClose()
all looks good to me, though keep in mind im not a js/ts dev
fair enough
And this was working seamlessly for close to a year...
updated any deps recently?
are you using private networking?
Private networking needs to be set correct? I haven't manually set it to private
This exact issue was happening with the mongodb plugin before
So not a networking issue I believe
No deps updated
but are you actively utilizing the private networking?
Is private networking active by default?
I just started this project from a template and haven't made any networking adjustements manually
its on by default, but im asking if you use it
Not actively using it
disable it
Sure
most recent deploy logs:
okay let me know if anything improves with private networking disabled
Currently building
What's your background? Thakns for being so helpful btw 🙂
i have no background, in tech at least
last job was a landscaper
lol that counts
How did you get involved in techy stuff?
uh id probably say arduino
Nice!
Okay so interesting now
Several errors in order:
you can connect to mongo from something like dbgate right?
I think so
check again
i have to go do some plumbing, ill be back in a bit
I'm gonna go at this from scratch again, removing everything but the google init and logging everywhere
all good, see ya!
What did it end up being? Did it just work after disabling the private network?
No
So, I had another module trying to run a test script on import. -_-
Solution
The test script was trying to connect and close at the same time
Just forgot to comment it out once I was done with local testing
How can I mark this solved?
glad you've solved it!