PollingObserver misses some new files when previously seen files are removed
Author: smolaCreated Jun 29, 2023Updated Sep 23, 2026
I'm observing missing events for newly created files in the following scenario:
- Process 1 is creating files in a directory.
- Process 2 is observing the directory with PollingObserver, whenever it sees file
X, it createsX.processedand removesX. - Tested on Linux with ext4.
Here's a gist with code to reproduce the issue: https://gist.github.com/smola/d40614a9b546a650d87bc3588efc1014
Apparently, under these fast create/deletes, the operating system is reusing inodes for new files, and they are being detected as file moves, rather than creations: https://github.com/gorakhargosh/watchdog/blob/48c49a1fe0538be455d52aa9a0eb57519a6ce2eb/src/watchdog/utils/dirsnapshot.py#L112-L117
However, the moves are arbitrary. For example, it detects a move from 87 to 83.processed. A possible workaround is looking for creation, modified events, and also moves (with dest_path in this case).
Source: gorakhargosh/watchdog