Connection pools must propagate connection errors
-
If you are writing a connection pool and someone calls
pool.getConnection()for the first time, your connection pool will at some point need to internally call some internal method likethis._createConnection(). -
If the internal
_createConnection()method throws an error, you need to make sure that that specific error gets plumbed up to the caller of the publicpool.getConnection()method. Error chaining is usually ideal. -
You still need to make sure this happens even if
_createConnection()was called internally *before*pool.getConnection()was ever called, which is a common situation if your pool eagerly opens connections on start. - If you do not do this AND you don't log connection errors anywhere THEN all connection error information gets discarded and hence all connection issues will show up as something completely uselessly nonspecific like "pool timeout: failed to retrieve a connection from pool after 10000ms",
- instead of what the actual problem is,
- and now I'm debugging in the dark.
(In practice it'll usually be fine if you attach any recent error from any relevant _createConnection() call. It doesn't really have to be a specific one: most of the time when connection settings are misconfigured it'll result in every connection attempt having a more-or-less identical error anyway.)
It's very upsetting to have to patch your dependencies to add missing error logging in the middle of an outage.
© Copyright 2026 Richard Barrell