The File-Watching Race Condition That Only Shows Up in Production
Описание и применение
Проблема: файловый наблюдатель пропускает файлы, если они созданы до его запуска, что приводит к пропущенным логам и подтверждениям. Решение: запускать наблюдатель и запись файла параллельно, гарантируя, что наблюдатель уже слушает события. Это устраняет гонку и повышает надёжность.
Задача
File watchers miss files if the file is created before the watcher starts, causing missing logs and silent failures in production.
Результат
By starting the watcher and writer simultaneously, the system reliably captures log files, preventing missing confirmations and silent failures.
Рабочий процесс
- 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
Доказательства
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.
- Дата записи: 2026-09-22T10:45:48.201Z