Effect fixes your TypeScript · Part 8
You're leaking database connections
Connect, query, release: if the query throws, release never runs, and after ten failures the pool is exhausted. Effect.acquireRelease guarantees release on success, failure and interruption, in reverse order.
Comment below: Ever hit pool exhaustion in production?
Effect fixes your TypeScript: a series on the bugs you already ship, and how Effect makes them impossible. All code is real Effect v4 and was compiled before it went on screen. https://effect.website
Transcript
You're leaking database connections. Here's the line. Connect, query, release. Looks right, but if the query throws, release never runs. Every failure keeps a connection forever. Your pool has 10. After 10 bad requests, the app just hangs at 3:00 a.m. So, you add try/finally, then a second resource, then nesting, and one wrong order leaks again. In Effect, Effect.acquireRelease. You acquire the connection and say how to release it in the same place. Effect guarantees the release runs on success, on failure, and on interruption, like the timeout from part six. Several resources? Released in reverse order, automatically. Best practice, never acquire something without saying how it's released, right there. The connection is safe. The data coming out of it? You're casting it with "as User". Part nine, ever hit pool exhaustion in production?




