bun icon indicating copy to clipboard operation
bun copied to clipboard

Mongoose serverless Atlas connection fails after +20 minutes

Open cachac opened this issue 1 year ago • 4 comments

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 <DATABASE_IP>:27017 closed

Additional information

Mongoose version 8.1.1

NodeJS works fine

cachac avatar Feb 01 '24 02:02 cachac

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

Jarred-Sumner avatar Feb 01 '24 08:02 Jarred-Sumner

@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

cirospaciari avatar Feb 01 '24 18:02 cirospaciari

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

akirarika avatar Feb 09 '24 00:02 akirarika

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

cachac avatar Feb 12 '24 06:02 cachac

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

cheong12001 avatar Mar 01 '24 17:03 cheong12001

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

Jarred-Sumner avatar Jun 28 '24 09:06 Jarred-Sumner