oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.5k stars 2.71k forks source link

Mongoose serverless Atlas connection fails after +20 minutes #8609

Closed cachac closed 3 months ago

cachac commented 8 months ago

What version of Bun is running?

1.0.25+a8ff7be64

What platform is your computer?

Linux 6.5.6-76060506-generic x86_64 x86_64

What steps can reproduce the bug?

A working demo here: https://github.com/cachac/bunJS-Mongoose

bun install mongoose

Connect to Database

const strconn = `mongodb+srv://<user>:<password>@<SERVERLESS_URL>/<DB_NAME>?retryWrites=true&w=majority`
const db = mongoose.connection

return mongoose.connect(strconn, {})

The connection opens normally, but sometimes if you wait some minutes (about 20 minutes), the connection is closed and the request fails.

Already tried some configurations like:

 socketTimeoutMS: 30000,
 connectTimeoutMS: 5000,
 maxPoolSize: 200
...

What is the expected behavior?

Connections stay open all the time

What do you see instead?

error: connection 28 to :27017 closed

Additional information

Mongoose version 8.1.1

NodeJS works fine

Jarred-Sumner commented 8 months ago

@cirospaciari is it possible there's some TLS thing we need to do every 20 minutes? something involving sessions

cirospaciari commented 8 months ago

@cirospaciari is it possible there's some TLS thing we need to do every 20 minutes? something involving sessions

sessions and handshakes should be automatic handled after the first one, need to check the docs but is probably missing something that keeps alive the connection probably related: https://stackoverflow.com/questions/11928151/mongoose-output-the-error-error-connection-closed

akirarika commented 7 months ago

I encountered a similar problem as you, but the error seems to have disappeared after updating to version 1.0.26. I hope my experience can help you

cachac commented 7 months ago

I encountered a similar problem as you, but the error seems to have disappeared after updating to version 1.0.26. I hope my experience can help you

Thanks @akirarika, but in my case the error is still in version 1.0.26

cheong12001 commented 7 months ago

i encounter the same problem with bun version 1.0.28. any update on this issue ? just update my app with bun in production. but this critical issue force me to rollback to old framework

Jarred-Sumner commented 3 months ago

This was likely fixed by @cirospaciari's change to SSL_write in #11849

I'm going to close this, but if you're still running into this on Bun v1.1.12 or later please leave a comment and we'll re-open