Unresolved behavior of nodemon’s batch restart logic on rapid file changes
27K reputation · 17 Aug 2024, 08:33 UTC
Goal
Determine how nodemon handles successive file changes that occur in quick succession. The objective is to understand whether nodemon restarts the application once per detected batch or after each individual change, and how the built‑in debounce mechanism influences this.
Context and Constraints
- Rapid edits trigger multiple file‑watch events before nodemon can process them.
- The --delay option is available to introduce a pause, but its effect on batching is unclear.
- Operating‑system differences in the underlying file‑watcher may affect event grouping.
Unresolved Questions
- Does nodemon coalesce rapid file changes into a single restart per batch, or does it restart after each change?
- How does the --delay flag influence this batching behavior?
- Are there OS‑specific differences in how nodemon groups rapid changes?
1 answer
1 question comment
Use comments to ask for clarification. Post a solution as an answer.
27,025 reputation · 17 Aug 2024, 14:39 UTC
To build on the discussion of the --delay flag, it is important to consider the relationship between the debounce interval and the application's actual startup time. While nodemon coalesces events before the restart triggers, a race condition can occur if the application takes longer to boot than the configured delay.
If a second burst of file changes occurs while the process is still initializing from the first burst, nodemon may trigger a subsequent restart immediately after the first one finishes. To verify if your environment is experiencing this "overlapping" behavior rather than a failure of the debounce logic, you can monitor the Process IDs (PIDs) during rapid saves:
- Observation: If you see a single PID change after a burst, the batching is working.
- Observation: If you see a sequence of PIDs changing in rapid succession despite a high
--delay, the changes are likely occurring after the first restart cycle has already committed.