Repository navigation
Map timeout and cancellation SQLSTATEs to transient - #750
dreamstar-enterprises wants to merge 1 commit into
Conversation
25P04 (transaction_timeout) now maps to R2dbcTimeoutException. 55P03 (lock_not_available) and 57014 (query_canceled) now map to R2dbcTransientResourceException rather than falling through to R2dbcNonTransientResourceException. [resolves #739]
|
Thanks a lot. Looking at the overall exception mapping, we seem to have quite a mismatch between what the error label says (this was the primary guide we used during mapping) and how the server behaves. For example, I think the entire mapping requires a larger revision that we can only ship with a new minor release because we would change behavior quite significantly in terms of exceptions. Here's a collection of other exception mapping cases:
Changes
The somewhat fuzzy nature (also 57014/55P03) where either context of the localized message governs the exception nature makes it really difficult to come up with a proper mapping and arguing about which problem bucket to assign an exception to works in either direction. So coming back to your initial proposal, it likely makes sense to be pragmatic and consider the most common cause for error codes instead of trying to be right but still making the wrong choice because in most cases, a different exception class would be the better choice. |
|
Hi Mark, Ok, it sounds sensible to do a closer examination running up to a minor release. I don't have much experience with the details of the driver - the mapping of states was something I picked up when If it helps, this is what I ended up doing, in a Kotlin/Spring WebFlux. Initial Mapping The exception type alone wasn't enough to decide a status, so I read the SQLSTATE first, then fall back to the val status = when {
// a plpgsql RAISE EXCEPTION with no ERRCODE of its own
sqlState == "P0001" -> null
// internal_error
sqlState == "XX000" -> HttpStatus.INTERNAL_SERVER_ERROR
// no_data_found
sqlState == "P0002" -> HttpStatus.NOT_FOUND
// statement_timeout, lock_timeout, idle_in_transaction_session_timeout, transaction_timeout
sqlState in setOf("57014", "55P03", "25P03", "25P04") -> HttpStatus.GATEWAY_TIMEOUT
// class 08, connection_exception
sqlState?.startsWith("08") == true -> HttpStatus.SERVICE_UNAVAILABLE
// class 40, transaction_rollback
sqlState?.startsWith("40") == true -> HttpStatus.CONFLICT
// class 53, insufficient_resources
sqlState?.startsWith("53") == true -> HttpStatus.SERVICE_UNAVAILABLE
// anything else: decided by the exception type Spring gave it (see the type mapping further below)
else -> ex.httpStatus()
}Points
Class 40: Secondary Mapping This is how a SQLSTATE reach me, which I read off r2dbc-postgresql 1.1.1 The My type fallback is: internal fun DataAccessException.httpStatus(): HttpStatus = when (this) {
is DuplicateKeyException -> HttpStatus.CONFLICT
is DataIntegrityViolationException -> HttpStatus.CONFLICT
is PermissionDeniedDataAccessException -> HttpStatus.FORBIDDEN
is TransientDataAccessResourceException -> HttpStatus.SERVICE_UNAVAILABLE
is DataAccessResourceFailureException -> HttpStatus.BAD_REQUEST
is CannotAcquireLockException -> HttpStatus.CONFLICT
is PessimisticLockingFailureException -> HttpStatus.CONFLICT
is QueryTimeoutException -> HttpStatus.SERVICE_UNAVAILABLE
// the query itself is wrong: my fault, not the caller's
is BadSqlGrammarException -> HttpStatus.INTERNAL_SERVER_ERROR
is UncategorizedR2dbcException -> HttpStatus.INTERNAL_SERVER_ERROR
is EmptyResultDataAccessException -> HttpStatus.NOT_FOUND
else -> HttpStatus.BAD_REQUEST
}Points To some of the other points: Class 22 to
Class 26: I am not entirely sure Of course I can change my own mapping to suit. Happy to help / support however I can. Thank you, -S |
Make sure that:
Issue description
Resolves #739.
25P04→R2dbcTimeoutException55P03,57014→R2dbcTransientResourceExceptionPreviously all three fell through to
R2dbcNonTransientResourceException.New Public APIs
None. The new classes are package-private, like the existing ones.
Additional context
Behaviour change: in Spring,
55P03and57014move fromDataAccessResourceFailureExceptiontoTransientDataAccessResourceException, and25P04toQueryTimeoutException. Neither is a subclass of the old type, so existingcatchblocks for it stop matching. Suggestmainonly.