Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't throw error on release expired lock #325

Merged
merged 3 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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