K
Kysely•17mo ago
bombillazo

Destroying connection necessary?

Hello! If we are using pooling via pgbouncer and using kysely from our edge functions, is it necessary to explicitly destroy the kysely instance/connection at the end to the function? Im asking since at the moment if an error is thrown, the instance is never explicitly destroyed. In local dev we dont have pgbouncer so we connect directly to the DB. After a while during dev and testing, the DB give a too many connections error.
1 Reply
Igal
Igal•17mo ago
Hey 👋 Different serverless environments behave or require different practices. e.g. it's considered a best practice to instantiate resources in global scope and re-use them between lambda invocations in AWS lambdas. iirc CF workers require creating and destroying any state within a single invocation, so I'd follow their guidelines, regardless of using PG bouncer or not. This'll require using a finally block that destroys the instance for now, starting from TypeScript 5.2 you'll have the convenience of using keyword (hopefully we'll be able to implement support for it with ease). Again, if anybody has better info on this, please correct me. I haven't shipped CF workers to production IRL. You could also ask in CloudFlare's official discord server.
Want results from more Discord servers?
Add your server