Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inotify event order/duplication, fix #117 and #233 #375

Merged
merged 4 commits into from
Oct 26, 2016

Conversation

danilobellini
Copy link
Collaborator

Add 2 new tests that addresses #117 and #233, fix them and fix a DirDeletedEvent duplication found on Linux when deleting a directory:

  • Fix the issue by removing the observers.inotify_c.Inotify._remove_watch_bookkeeping helper method, as it would mix wd and src_path when removing a path that was assigned to more than one wd. The items on the wd to/from src_path mappings are still being removed, but consistently and inlined;
  • Add a test with a [fast] directory creation and deletion cycle. On Linux, after fixing the related code, the DirDeletedEvent was emitted twice as both the IN_DELETE|IS_DIR event and the IN_DELETE_SELF event were triggering a watchdog event, that was fixed by removing the latter event;
  • Add a test for the inotify emitter in a corner case, where a directory is created and deleted twice before emitting the first IN_DELETE_SELF, mocking the Inotify API for that. This test doesn't depend on randomness/speed). The mock/monkeypatch required another test module to properly stop the emitter.

The IN_DELETE_SELF is a directory-only event, so this inotify event doesn't have an IS_DIR flag. The former code that evaluated cls = DirDeletedEvent if event.is_directory else FileDeletedEvent on such an event is an evidence that it wasn't being tested.

- This is related to gorakhargosh#117 and gorakhargosh#233
- It's about a single path that is has 2 wd values, i.e., a
  subdirectory path that was created again before the "bookkeeping
  removal" event (IN_IGNORE) of a deletion was processed
- The test is using a stochastical approach to reach the bug, in the
  sense that being "fast" isn't enough to enforce a particular event
  order; however, a "lucky" event synchronization seems extremely rare
  and the package should pass on every case
- Even with an unknown order for the events, the test is counting and
  enforces:
  - Watchdog emits the 120 events that happened
  - Specific number of events for each type
  - Order constraing as required for minimal consistency (e.g. not
    deleting a directory that wasn't created)
- The call on inotify_event.is_ignored was removing the wrong wd, due
  to another wd with the same path (self._wd_for_path[src_path] was
  replaced)
- Fix gorakhargosh#117 and gorakhargosh#233
- Still not enough to fix every bug regarding fast/unordered events,
  but doesn't crash anymore
c = IN_CREATE|IS_DIR
d = IN_DELETE|IS_DIR
ds = IN_DELETE_SELF
i = IN_IGNORE

These are inotify events, not watchdog events

The new test is written in a new module because it required a
different teardown function to stop the emitter before undoing
the mock
Inotify emits a IN_DELETE|IS_DIR event and a IN_DELETE_SELF event (in
this order) when a watched directory is removed, the former event
happens for all directories and generates a pair of a DirDeletedEvent
and a DirModifiedEvent instances, the latter used to generate a
(duplicated and unrequired) DirDeletedEvent

With this change, the test_fast_subdirectory_creation_deletion no
longer fails
@danilobellini
Copy link
Collaborator Author

I'm testing this with #368. Before pushing, I've checked that the tests are passing on all environments. Commands like tox -e py27 -- -k inotify_c were quite handy to fastly evaluate the related test while coding. These commits were rebased from the tox branch to the master branch just to create this PR.

@danilobellini
Copy link
Collaborator Author

Since 17 Aug, this fix is also in a patch applied by dose to use watchdog.

@danilobellini
Copy link
Collaborator Author

I wonder why no one commented on this PR yet.

@DonyorM
Copy link
Contributor

DonyorM commented Oct 26, 2016

Thank you for spending the time to fix these issues.

Sorry that we took so long to get around to answering, I didn't know I was the only one looking at these.

@DonyorM DonyorM merged commit 86e7250 into gorakhargosh:master Oct 26, 2016
CCP-Aporia pushed a commit to CCP-Aporia/watchdog that referenced this pull request Aug 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants