From 94f95ca6b8f0ab8cd6c9f7853d24a7cdcbca51d0 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 12 Dec 2025 12:33:38 +0100 Subject: [PATCH] :bug: Fix incorrect redis connection error handling --- backend/src/app/worker/dispatcher.clj | 49 ++++++++++++++------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/backend/src/app/worker/dispatcher.clj b/backend/src/app/worker/dispatcher.clj index f95ade8e1c..818c50c18c 100644 --- a/backend/src/app/worker/dispatcher.clj +++ b/backend/src/app/worker/dispatcher.clj @@ -137,33 +137,34 @@ RETURNING task.id, task.queue") ::wait))) (run-batch [] - (let [rconn (rds/connect cfg)] - (try - (-> cfg - (assoc ::rds/conn rconn) - (db/tx-run! run-batch')) + (try + (let [rconn (rds/connect cfg)] + (try + (-> cfg + (assoc ::rds/conn rconn) + (db/tx-run! run-batch')) + (finally + (.close ^AutoCloseable rconn)))) - (catch InterruptedException cause - (throw cause)) - (catch Exception cause - (cond - (rds/exception? cause) - (do - (l/wrn :hint "redis exception (will retry in an instant)" :cause cause) - (px/sleep timeout)) + (catch InterruptedException cause + (throw cause)) - (db/sql-exception? cause) - (do - (l/wrn :hint "database exception (will retry in an instant)" :cause cause) - (px/sleep timeout)) + (catch Exception cause + (cond + (rds/exception? cause) + (do + (l/wrn :hint "redis exception (will retry in an instant)" :cause cause) + (px/sleep timeout)) - :else - (do - (l/err :hint "unhandled exception (will retry in an instant)" :cause cause) - (px/sleep timeout)))) + (db/sql-exception? cause) + (do + (l/wrn :hint "database exception (will retry in an instant)" :cause cause) + (px/sleep timeout)) - (finally - (.close ^AutoCloseable rconn))))) + :else + (do + (l/err :hint "unhandled exception (will retry in an instant)" :cause cause) + (px/sleep timeout)))))) (dispatcher [] (l/inf :hint "started") @@ -176,7 +177,7 @@ RETURNING task.id, task.queue") (catch InterruptedException _ (l/trc :hint "interrupted")) (catch Throwable cause - (l/err :hint " unexpected exception" :cause cause)) + (l/err :hint "unexpected exception" :cause cause)) (finally (l/inf :hint "terminated"))))]