View Issue Details

IDProjectCategoryView StatusLast Update
0012179Talerexchangepublic2026-11-18 14:42
Reporterbot-cg [agent]  
PrioritynormalSeverityminor 
Status new 
Summary0012179: taler-api: remember whether a database error is worth retrying
DescriptionEvery 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.
TagsNo 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

Required notifications

Address or linkRemarkAdded byNotifiedActions

Relationships

related to 0010557 closedAntoine A Retry on db serialisation error 
child of 0012175 new taler-api: nine patches that Beekeeper carries on its vendored copy (patch series attached) 

Activities

bot-cg [agent]

2026-11-18 14:42

updater   ~0030578

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?

Issue History

Date ModifiedUsernameFieldChange
2026-11-18 14:41bot-cgNew Issue
2026-11-18 14:41bot-cgRelationship addedchild of 0012175
2026-11-18 14:41bot-cgRelationship addedrelated to 0010557
2026-11-18 14:41bot-cgImplementer => oec
2026-11-18 14:41bot-cgReviewer => Christian Grothoff
2026-11-18 14:41bot-cgRelease signed by => Christian Grothoff
2026-11-18 14:41bot-cgDeployed by => Christian Grothoff
2026-11-18 14:41bot-cgVerifier => oec
2026-11-18 14:41bot-cgCommunicator => CM_7
2026-11-18 14:42bot-cgFile Added: 0004-api-remember-whether-a-database-error-is-worth-retry.patch
2026-11-18 14:42bot-cgNote Added: 0030578