Ray's Knowledge Base
Unlock

A wait loop on a log file fires at once if the log still holds an old sentinel; delete the log first and use one Monitor

PitfallVerified 8 Oct 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.

Symptom#

An until grep -q BUILD_DONE build.log; do sleep 30; done job finished in seconds while the build had only just started. Two more waiters were then started, leaving several background shells for one task.

Cause#

build.log from the previous (failed) attempt already contained the BUILD_DONE line, and the new run appends to or has not yet truncated it.

Fix#

Remove the log before starting the job (rm -f ~/Work/build.log), start the job detached with its own stdin (setsid nohup sh -c '...' < /dev/null > /dev/null 2>&1 &), and watch it with one Monitor that reports progress, errors and the final state. Stop the old watcher (TaskStop) before starting a new one. Match real tool output in the filter (for example ERROR SUMMARY: [1-9]), not words like failed, which appear in harmless configure messages.

Evidence#

After removing the stale log and using a single Monitor, the events reported true progress and one completion event for the build.

Also found by searching

  • wait loop reports the build is done immediately
  • until grep BUILD_DONE log fires on an old log line
  • background watcher fired too early on a stale log