Skip to content

Commit 2f65df3

Browse files
sjarmakclaude
andcommitted
fix: temp dir race condition in MCP Dockerfile swap
Background cleanup watcher used wait() on PIDs from the parent shell, but wait() only works for child processes of the calling subshell. The cleanup subshell's wait() returned immediately, deleting the temp dir before Harbor could read it. Every MCP launch hit FileNotFoundError. Fix: collect temp dirs in _MCP_TEMP_DIRS array, clean them up in _drain_pool() which runs in the parent shell and can properly wait for all harbor PIDs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4fd7aad commit 2f65df3

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

configs/run_selected_tasks.sh

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -337,13 +337,21 @@ _wait_for_slot() {
337337
done
338338
}
339339

340-
# Wait for all pending jobs to complete
340+
# Temp dirs created for MCP Dockerfile swap — cleaned up in _drain_pool
341+
_MCP_TEMP_DIRS=()
342+
343+
# Wait for all pending jobs to complete, then clean up temp dirs
341344
_drain_pool() {
342345
local p
343346
for p in "${_PIDS[@]}"; do
344347
wait "$p" 2>/dev/null || true
345348
done
346349
_PIDS=()
350+
# Clean up MCP temp dirs now that all harbor processes are done
351+
for d in "${_MCP_TEMP_DIRS[@]}"; do
352+
rm -rf "$d" 2>/dev/null || true
353+
done
354+
_MCP_TEMP_DIRS=()
347355
}
348356

349357
# Launch a task PAIR: baseline + full simultaneously for the same task.
@@ -431,15 +439,10 @@ _launch_task_pair() {
431439
sleep 2
432440
fi
433441

434-
# Background watcher: clean up temp dir after MCP config completes.
435-
# Not counted in _PIDS (it's cleanup, not a work slot).
436-
if [ -n "$_mcp_temp_dir" ] && [ "${#pair_pids[@]}" -gt 0 ]; then
437-
(
438-
for p in "${pair_pids[@]}"; do
439-
wait "$p" 2>/dev/null || true
440-
done
441-
rm -rf "$_mcp_temp_dir" 2>/dev/null || true
442-
) &
442+
# Track temp dir for cleanup in _drain_pool (after all harbor processes finish).
443+
# Cannot use background watcher because wait() only works for child processes.
444+
if [ -n "$_mcp_temp_dir" ]; then
445+
_MCP_TEMP_DIRS+=("$_mcp_temp_dir")
443446
fi
444447
}
445448

0 commit comments

Comments
 (0)