Skip to content

Commit 4baef39

Browse files
Merge pull request #1721 from AxiomCodeAI/fix/souffle-compile-lock
run-souffle: one engine compile per engine id
2 parents fdcc99e + 1b2db3e commit 4baef39

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

‎graph/pipeline/run-souffle.sh‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,22 @@ if [ -n "$PACKAGED" ]; then
600600
elif [ -x "$BIN" ]; then
601601
echo "▶ reusing cached binary"
602602
elif command -v souffle >/dev/null 2>&1; then
603+
# ONE COMPILE PER ENGINE ID. Concurrent runs that miss the cache together (a suite's
604+
# concurrent cases, several agents on one machine) each compiled the same engine: a
605+
# multi-GB c++ per run, enough of them at once to exhaust memory. The first takes the
606+
# lock and compiles; the others wait, then reuse its binary. A lock older than 30 min
607+
# is a dead compile's (killed, out of memory) and is taken over.
608+
COMPILE_LOCK="$BIN.lock"; _waited=0
609+
until mkdir "$COMPILE_LOCK" 2>/dev/null; do
610+
if [ -n "$(find "$COMPILE_LOCK" -maxdepth 0 -mmin +30 2>/dev/null)" ]; then rmdir "$COMPILE_LOCK" 2>/dev/null || true; continue; fi
611+
[ "$_waited" = 1 ] || echo "▶ another run is compiling this engine; waiting for it..."
612+
_waited=1; sleep 3
613+
done
614+
trap 'rmdir "$COMPILE_LOCK" 2>/dev/null || true' EXIT
615+
fi
616+
if [ -z "$PACKAGED" ] && [ -x "$BIN" ] && [ -n "${COMPILE_LOCK:-}" ]; then
617+
echo "▶ reusing the binary another run compiled"
618+
elif [ -z "$PACKAGED" ] && [ -n "${COMPILE_LOCK:-}" ]; then
603619
echo "▶ compiling souffle program (cache miss)..."
604620
INNER="$(find_souffle_include)"
605621
# Assert the HEADER, not the directory: `[ -d ]` is the test #216 established cannot tell
@@ -636,7 +652,9 @@ elif command -v souffle >/dev/null 2>&1; then
636652
exit 1
637653
fi
638654
mv -f "$BIN.tmp.$$" "$BIN"
639-
else
655+
fi
656+
if [ -n "${COMPILE_LOCK:-}" ]; then rmdir "$COMPILE_LOCK" 2>/dev/null || true; trap - EXIT
657+
elif [ -z "$PACKAGED" ] && [ ! -x "$BIN" ]; then
640658
echo "❌ no engine for $LANG_ARG@${ENGINE_ID:0:12}… on this machine. Either:" >&2
641659
echo " • run \`npm install\` here — it fetches $ENGINE_PACKAGE_SCOPE/engine-<platform> for this machine (if these rules have been published), or" >&2
642660
echo " • install souffle $SOUFFLE_VERSION to compile locally (macOS: brew install souffle; Ubuntu: the .deb from souffle-lang/souffle releases)." >&2

0 commit comments

Comments
 (0)