Skip to content

Commit d996f7b

Browse files
authored
Merge pull request #6 from KingPin/fix/project-lock-fd-leak
fix(lock): stop orphaned compose children from pinning the project lock
2 parents 3705414 + 3d43a80 commit d996f7b

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

hoist.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
HOIST_VERSION="1.8.2"
2+
HOIST_VERSION="1.8.3"
33
HOIST_REPO="KingPin/hoist"
44

55
DOCKER_BINARY="${DOCKER_BINARY:-$(which docker)}"
@@ -363,7 +363,17 @@ _with_project_lock() {
363363
local fd
364364
exec {fd}>"$lock" || { log "Error: cannot open project lock $lock"; return 1; }
365365
flock "$fd"
366-
"$@"; rc=$?
366+
# The flock is held against the open file description, not this process,
367+
# and bash sets no close-on-exec on {var}> fds — so the docker/compose
368+
# child run below would otherwise inherit $fd and keep the lock held even
369+
# after this worker dies. A Ctrl+C mid-`docker compose pull` then orphans
370+
# that pull (reparented to init) holding the inherited fd, wedging every
371+
# later run that touches this project on `flock` forever. Close $fd for
372+
# the command only ({fd}>&-): this worker keeps its own copy open so the
373+
# lock stays held for the pull/up, but the docker child cannot pin it —
374+
# an orphaned pull no longer survives its worker. (Same fd-inheritance
375+
# hazard the run lock handles via its childless holder process.)
376+
"$@" {fd}>&-; rc=$?
367377
exec {fd}>&-
368378
return "$rc"
369379
fi

0 commit comments

Comments
 (0)