The File-Watching Race Condition That Only Shows Up in Production
Description and use
Problem: File watchers miss files created before they start, causing silent failures. Fix: start the watcher and file write in parallel so the watcher is listening before the file is created, eliminating the race condition.
Problem
File watchers miss files if the file is created before the watcher starts, causing missing logs and silent failures in production.
Outcome
By starting the watcher and writer simultaneously, the system reliably captures log files, preventing missing confirmations and silent failures.
Workflow
- Start file watcher (watch_log_creation) and file write (write_order_log) in parallel
- Configure watcher to monitor /logs/orders for *.log entries
- Set watchDuration to 20000 ms to detect missing files
- Process log file once watcher signals creation
Evidence
The watcher has to already be listening before the file lands. Get that backwards, even by a few milliseconds, and the file just slips through.
The fix is to kick off "start watching" and "write the file" at the same moment, as two things happening in parallel instead of one after the other.
- Record date: 2026-09-22T10:45:48.201Z