Skip to content

Commit

Permalink
Don't throw error on release expired lock (#325)
Browse files Browse the repository at this point in the history
* Don't throw error on release expired lock

* Log error when lock lost in extend

* Added nve suppression
  • Loading branch information
mdemare authored Aug 28, 2024
1 parent 1b535ee commit 014765c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .nvd-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
<notes>Using clojure higher than 1.9.0 and not earlier as implied by some dependencies.</notes>
<cve>CVE-2017-20189</cve>
</suppress>
<suppress>
<notes>We don't use zgrep</notes>
<cve>CVE-2022-1271</cve>
</suppress>
</suppressions>
10 changes: 6 additions & 4 deletions src/nl/surf/eduhub_rio_mapper/worker.clj
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
lua-result (car/wcar redis-conn (car/lua lua-script {:k k} {:token token}))]
(assert (number? lua-result))
(when (not= 1 lua-result)
(throw (ex-info "Lock lost before release!" {:lock-name k})))))
(log/error (str "Lock " k " lost before release!")))))

(defn extend-lock!
"Extend TTL on lock on `queue` with `token` by `ttl-ms`.
Expand All @@ -79,7 +79,7 @@
lua-result (car/wcar redis-conn (car/lua lua-script {:k k} {:token token, :ttl-ms ttl-ms}))]
(assert (number? lua-result))
(when (not= 1 lua-result)
(throw (ex-info "Lock lost before extend!" {:lock-name k})))))
(log/error (str "Lock lost before extend!" {:lock-name k})))))

(defn- queue-key [config queue]
(prefix-key config (str "queue:" queue)))
Expand Down Expand Up @@ -202,7 +202,8 @@
retryable-fn
run-job-fn
set-status-fn]
:or {lock-ttl-ms 10000
;; Set lock expiry to 1 minute; locks in production have unexpectedly expired with shorter intervals
:or {lock-ttl-ms 60000
nap-ms 1000}} :worker
:as config}
stop-atom]
Expand All @@ -212,7 +213,8 @@
(fn? run-job-fn) (fn? set-status-fn)
(ifn? retryable-fn) (ifn? error-fn) (ifn? queue-fn)]}

(let [timeout-ms (/ lock-ttl-ms 2)]
;; Extend lock at least each second
(let [timeout-ms (min 1000 (/ lock-ttl-ms 2))]
(loop [queues (occupied-queues config)]
(if-let [[queue & queues] queues]
(do
Expand Down

0 comments on commit 014765c

Please sign in to comment.