Skip to content

Commit e19af10

Browse files
committed
fix(memoize): release flock before early return on cache hit
run_memoized() opens the lock via `exec {lock_fd}>`, a process-level fd that is not closed when the function returns. The cache-hit path did `source "${disk_cache_file}"; return 0` without the `flock -u` that the memoize/write path performs before its own return, leaking the advisory lock (and the fd) on every cache hit. Pre-existing, but the new OFFLINE_WORK stale-serve path now takes this early return for stale entries too (previously stale => deleted => fall-through to the unlocking path), so it fires far more often. A second run_memoized() for the same key in one process would then block until MEMOIZE_FLOCK_MAX_WAIT. Release the lock before the early return. Assisted-by: Claude:claude-opus-4.8
1 parent 3487079 commit e19af10

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

lib/functions/general/memoize-cached.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ function run_memoized() {
9797
display_alert "Using cached" "${var_n}" "info"
9898
# shellcheck disable=SC1090 # yep, I'm sourcing the cache here. produced below.
9999
source "${disk_cache_file}"
100+
flock -u "${lock_fd}"
100101
return 0
101102
fi
102103
fi

0 commit comments

Comments
 (0)