How do you set a timeout for pool.Acquire
in pgxpool, so that if the pool is full we can fail fast?
#2185
-
Hello, I am using pgxpool (with pgx v5.6.0) for connection pooling. I want to set a timeout on the operation that acquires the connection from the pool, so that if all the connections in the pool are busy for a long period for whatever reason, we fail fast and early. I know that if I set a tracer which satisfies the tracer interface, in the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
If you're directly calling Acquire on the pool then the regular context argument will do what you want. If Acquire is being called implicitly by another function like This might actually relate to #2163 and #2171. It just occurred to me that a possible improvement to all of these would be to allow passing a context as a value in another context. e.g. You pass a context to Query, but if that context has a Value with the key of AcquireContext, then that context is used for the Acquire instead of the context passed to Query. |
Beta Was this translation helpful? Give feedback.
If you're directly calling Acquire on the pool then the regular context argument will do what you want. If Acquire is being called implicitly by another function like
Query
, then there is no built-in / intended way to have a separate context passed to Acquire. Off the top of my head, I'm not sure if using a Tracer as you describe would work.This might actually relate to #2163 and #2171. It just occurred to me that a possible improvement to all of these would be to allow passing a context as a value in another context. e.g. You pass a context to Query, but if that context has a Value with the key of AcquireContext, then that context is used for the Acquire instead of the context passed to…