fix: ci_fix_count/ci_fix_increment not atomic — potential race under concurrent polls (#118)
Wrap ci_fix_count(), ci_fix_increment(), and ci_fix_reset() with flock on a shared lockfile to prevent concurrent modification of the JSON tracker. Uses flock(1) in command-wrapping mode so each Python process holds an exclusive lock for the duration of its read-modify-write cycle. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
23364c6c01
commit
1352620c3d
1 changed files with 4 additions and 3 deletions
|
|
@ -22,13 +22,14 @@ source "$(dirname "$0")/../lib/ci-helpers.sh"
|
||||||
|
|
||||||
# Track CI fix attempts per PR to avoid infinite respawn loops
|
# Track CI fix attempts per PR to avoid infinite respawn loops
|
||||||
CI_FIX_TRACKER="${FACTORY_ROOT}/dev/ci-fixes-${PROJECT_NAME:-harb}.json"
|
CI_FIX_TRACKER="${FACTORY_ROOT}/dev/ci-fixes-${PROJECT_NAME:-harb}.json"
|
||||||
|
CI_FIX_LOCK="${CI_FIX_TRACKER}.lock"
|
||||||
ci_fix_count() {
|
ci_fix_count() {
|
||||||
local pr="$1"
|
local pr="$1"
|
||||||
python3 -c "import json,sys;d=json.load(open('$CI_FIX_TRACKER')) if __import__('os').path.exists('$CI_FIX_TRACKER') else {};print(d.get(str($pr),0))" 2>/dev/null || echo 0
|
flock "$CI_FIX_LOCK" python3 -c "import json,sys;d=json.load(open('$CI_FIX_TRACKER')) if __import__('os').path.exists('$CI_FIX_TRACKER') else {};print(d.get(str($pr),0))" 2>/dev/null || echo 0
|
||||||
}
|
}
|
||||||
ci_fix_increment() {
|
ci_fix_increment() {
|
||||||
local pr="$1"
|
local pr="$1"
|
||||||
python3 -c "
|
flock "$CI_FIX_LOCK" python3 -c "
|
||||||
import json,os
|
import json,os
|
||||||
f='$CI_FIX_TRACKER'
|
f='$CI_FIX_TRACKER'
|
||||||
d=json.load(open(f)) if os.path.exists(f) else {}
|
d=json.load(open(f)) if os.path.exists(f) else {}
|
||||||
|
|
@ -38,7 +39,7 @@ json.dump(d,open(f,'w'))
|
||||||
}
|
}
|
||||||
ci_fix_reset() {
|
ci_fix_reset() {
|
||||||
local pr="$1"
|
local pr="$1"
|
||||||
python3 -c "
|
flock "$CI_FIX_LOCK" python3 -c "
|
||||||
import json,os
|
import json,os
|
||||||
f='$CI_FIX_TRACKER'
|
f='$CI_FIX_TRACKER'
|
||||||
d=json.load(open(f)) if os.path.exists(f) else {}
|
d=json.load(open(f)) if os.path.exists(f) else {}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue