pgconn icon indicating copy to clipboard operation
pgconn copied to clipboard

fix: updating `SafeToRetry()` function to retry on wrapped errors

Open tjasko opened this issue 10 months ago • 0 comments

There is a rather unique bug when a single connection is being slammed with queries. When statement caching is enabled, and the deallocateInvalidatedCachedStatements() method is called to clean up, the Pipeline.Sync() method has the ability to error out due to the connection being in-use.

connLockError already implements the inexplicit SafeToRetry() bool() interface, which is then checked by the SafeToRetry() function. In the event the connection is locked due to being in use, the deallocateInvalidatedCachedStatements() method can return a wrapped error that looks like:

failed to deallocate cached statement(s): conn busy

When the stdlib PGX wrapper is used, it is possible for this to not be retried, as it is also taking advantage of this SafeToRetry() function. In order to correct this and prevent future similar errors, the SafeToRetry() function has been updated to check against the wrapped errors as well.

If approved, the change should be made in PGX as well: https://github.com/jackc/pgx/blob/v5.5.5/pgconn/errors.go#L13-L19

tjasko avatar Apr 24 '24 20:04 tjasko