From 5275c350023ffd6da7303aae22a41a050b87dfa1 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 24 Aug 2023 11:18:56 +0200 Subject: [PATCH 1/3] :bug: Prevent rollback for idle-in-transaction errors on cron tasks --- backend/src/app/worker.clj | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/backend/src/app/worker.clj b/backend/src/app/worker.clj index 05c27f7f8..1c7bcfd1b 100644 --- a/backend/src/app/worker.clj +++ b/backend/src/app/worker.clj @@ -574,8 +574,11 @@ (l/trace :hint "register cron task" :id id :cron (str cron)) (db/exec-one! conn [sql:upsert-cron-task id (str cron) (str cron)])))) -(def sql:lock-cron-task - "select id from scheduled_task where id=? for update skip locked") +(defn- lock-scheduled-task! + [conn id] + (let [sql (str "SELECT id FROM scheduled_task " + " WHERE id=? FOR UPDATE SKIP LOCKED")] + (some? (db/exec-one! conn [sql (d/name id)])))) (defn- execute-cron-task [{:keys [::db/pool] :as cfg} {:keys [id] :as task}] @@ -583,11 +586,16 @@ {:name (str "penpot/cront-task/" id)} (try (db/with-atomic [conn pool] - (when (db/exec-one! conn [sql:lock-cron-task (d/name id)]) + (db/exec-one! conn ["SET statement_timeout=0;"]) + (db/exec-one! conn ["SET idle_in_transaction_session_timeout=0;"]) + (when (lock-scheduled-task! conn id) (l/trace :hint "cron: execute task" :task-id id) - ((:fn task) task))) + ((:fn task) task)) + (db/rollback! conn)) + (catch InterruptedException _ (l/debug :hint "cron: task interrupted" :task-id id)) + (catch Throwable cause (binding [l/*context* (get-error-context cause task)] (l/error :hint "cron: unhandled exception on running task" From d80aa7593b0e795f1dc51cc854d283779f1bc831 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 24 Aug 2023 11:37:59 +0200 Subject: [PATCH 2/3] :bug: Fix unexpected exception on encoding error response --- backend/src/app/http/errors.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/app/http/errors.clj b/backend/src/app/http/errors.clj index 6ca7d7f68..4b22cb493 100644 --- a/backend/src/app/http/errors.clj +++ b/backend/src/app/http/errors.clj @@ -81,7 +81,7 @@ (let [explain (ex/explain data)] {::yrs/status 400 ::yrs/body (-> data - (dissoc ::s/problems ::s/value) + (dissoc ::s/problems ::s/value ::s/spec) (cond-> explain (assoc :explain explain)))}) (= code :params-validation) From aaf9c6e50bccfe6e9fe32cfaab894b4f69628e4e Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Thu, 24 Aug 2023 12:00:56 +0200 Subject: [PATCH 3/3] :sparkles: Enable access tokens by default --- backend/scripts/start-dev | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/scripts/start-dev b/backend/scripts/start-dev index a7f0045d1..d9ba4b1ce 100755 --- a/backend/scripts/start-dev +++ b/backend/scripts/start-dev @@ -15,7 +15,7 @@ export PENPOT_FLAGS="\ enable-fdata-storage-objets-map \ disable-secure-session-cookies \ enable-smtp \ - enable-webhooks"; + enable-access-tokens"; set -ex