View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0012179 | Taler | taler-rust | public | 2026-11-18 14:41 | 2026-11-18 15:57 |
| Reporter | bot-cg [agent] | ||||
| Implementer | Antoine A | ||||
| Fast-track | Yes — The control, the release and the deployment are skipped: whoever implemented this change verifies and closes it themselves. | ||||
| Priority | normal | Severity | trivial | ||
| Status | implementing | ||||
| Summary | 0012179: taler-api: remember whether a database error is worth retrying | ||||
| Description | Every connection runs with SERIALIZABLE isolation, so a handler that reads, decides and then writes can lose the race and has to repeat the whole thing; turning the sqlx error into an ApiError threw away the one bit that says so. Files: common/taler-api/src/error.rs (paths in the taler-rust tree). The patch is attached; it is number 4 of the series in the parent issue, against taler-rust 2c678873, and applies on top of the patches before it. | ||||
| Tags | No tags attached. | ||||
| Attached Files | 0004-api-remember-whether-a-database-error-is-worth-retry.patch (2,869 bytes)
From 48332fa76f4411f1500cca0593a660b74d097fb9 Mon Sep 17 00:00:00 2001
From: Christian Grothoff <christian@grothoff.org>
Date: Wed, 14 Oct 2026 16:15:14 +0200
Subject: [PATCH 4/9] api: remember whether a database error is worth retrying
Every connection runs with SERIALIZABLE isolation, so a handler that reads,
decides and then writes can lose the race and has to repeat the whole thing;
turning the sqlx error into an ApiError threw away the one bit that says so.
---
common/taler-api/src/error.rs | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/common/taler-api/src/error.rs b/common/taler-api/src/error.rs
index f6494ca..50bed41 100644
--- a/common/taler-api/src/error.rs
+++ b/common/taler-api/src/error.rs
@@ -136,6 +136,8 @@ pub struct ApiError {
path: Option<Box<str>>,
headers: Option<Box<HeaderMap>>,
extra: Option<Box<serde_json::value::RawValue>>,
+ /// Set when this was made from a database error that a retry can clear.
+ retryable: bool,
}
impl Display for ApiError {
@@ -158,9 +160,23 @@ impl ApiError {
path: None,
headers: None,
extra: None,
+ retryable: false,
}
}
+ /// Whether the database asked for the work to be done again: a
+ /// serialization failure or a deadlock (40001, 40P01) under the
+ /// `SERIALIZABLE` isolation every connection runs with.
+ ///
+ /// A handler that reads, decides and then writes cannot retry such a
+ /// failure where it happens -- the whole read-modify-write has to be
+ /// repeated on a snapshot that includes the other writer -- so the one
+ /// bit that says whether repeating it is worth anything has to survive
+ /// the trip up to it.
+ pub fn is_retryable(&self) -> bool {
+ self.retryable
+ }
+
pub fn with_hint(self, hint: impl Display) -> Self {
Self {
hint: Some(hint.to_string().into_boxed_str()),
@@ -210,6 +226,8 @@ impl ApiError {
impl From<sqlx::Error> for ApiError {
fn from(value: sqlx::Error) -> Self {
+ use crate::db::PgError;
+ let retryable = value.is_retryable_err();
let (code, status) = match value {
sqlx::Error::Configuration(_) => {
(ErrorCode::GENERIC_DB_SETUP_FAILED, StatusCode::BAD_GATEWAY)
@@ -230,6 +248,7 @@ impl From<sqlx::Error> for ApiError {
path: None,
headers: None,
extra: None,
+ retryable,
}
}
}
@@ -301,6 +320,8 @@ impl IntoResponse for ApiError {
path,
headers,
extra,
+ // Ours, not the client's business.
+ retryable: _,
} = self;
let status_code = status
.unwrap_or_else(|| StatusCode::from_u16(code.status()).expect("Invalid status code"));
--
2.47.3
| ||||
| Correction: this issue was filed in the category "exchange" by mistake. It concerns taler-rust (common/taler-api or common/taler-common), like its parent 0012175, and belongs in the category "taler-rust". This reporter account cannot change the category; could someone with updater rights move it? | |
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2026-11-18 14:41 | bot-cg | New Issue | |
| 2026-11-18 14:41 | bot-cg | Relationship added | child of 0012175 |
| 2026-11-18 14:41 | bot-cg | Relationship added | related to 0010557 |
| 2026-11-18 14:41 | bot-cg | Implementer | => oec |
| 2026-11-18 14:41 | bot-cg | Reviewer | => Christian Grothoff |
| 2026-11-18 14:41 | bot-cg | Release signed by | => Christian Grothoff |
| 2026-11-18 14:41 | bot-cg | Deployed by | => Christian Grothoff |
| 2026-11-18 14:41 | bot-cg | Verifier | => oec |
| 2026-11-18 14:41 | bot-cg | Communicator | => CM_7 |
| 2026-11-18 14:42 | bot-cg | File Added: 0004-api-remember-whether-a-database-error-is-worth-retry.patch | |
| 2026-11-18 14:42 | bot-cg | Note Added: 0030578 | |
| 2026-11-18 15:54 | Christian Grothoff | Category | exchange => taler-rust |
| 2026-11-18 15:56 | Christian Grothoff | Severity | minor => trivial |
| 2026-11-18 15:56 | Christian Grothoff | Status | new => implementing |
| 2026-11-18 15:57 | Christian Grothoff | Fast-track | 0 => 1 |
| 2026-11-18 15:57 | Christian Grothoff | Implementer | oec => Antoine A |