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

KeyError in read_events while executing shell command #233

Closed
jajadinimueter opened this issue Apr 23, 2014 · 4 comments
Closed

KeyError in read_events while executing shell command #233

jajadinimueter opened this issue Apr 23, 2014 · 4 comments
Labels

Comments

@jajadinimueter
Copy link

Hi!

I keep getting this exception while executing the following command

watchmedo shell-command -p "*.rst" -i build --ignore-directories -w -R -c bin/sphinx-build
Traceback (most recent call last):
  File "/usr/lib/python3.3/threading.py", line 637, in _bootstrap_inner
    self.run()
  File "/path/to/watchdog-0.7.1-py3.3.egg/watchdog/observers/api.py", line 187, in run
    self.queue_events(self.timeout)
  File /path/to/watchdog-0.7.1-py3.3.egg/watchdog/observers/inotify.py", line 135, in queue_events
    inotify_events = self._inotify.read_events()
  File "/path/to/watchdog-0.7.1-py3.3.egg/watchdog/observers/inotify_c.py", line 321, in read_events
    wd_path = unicode_paths.encode(self._path_for_wd[wd])
KeyError: 4007

I'm on version 0.7.1.

Do you need more information?

@jajadinimueter
Copy link
Author

I did just this for a temporary fix:

jajadinimueter@3c2be97

It works for me

@tamland
Copy link
Collaborator

tamland commented May 5, 2014

It would be nice to have a reproduceable example to find out why you are getting events for unknown watch descriptors instead of sweeping it under the rug. I have seen these errors before in logs, but not been able to find out what triggers it.

@tamland tamland added the linux label May 5, 2014
@danilobellini
Copy link
Collaborator

This is exactly #117. I've found this issue when running my dose project on my PyScanPrev project root directory with dose tox; that triggers the issue on every single run when using the specific commits in these links.

After spending some time looking for the "root path of all evil", I think I found a reproduceable example to trigger that issue: a really fast create-remove loop for the same directory name a few times (about 30, perhaps less) seems enough for a stochastical approach. I've already add that as a test, and I've found a solution for this issue about crashing. But I think that opened up a Pandora's box.

As it seems, that's an issue about a DELETE-CREATE-IGNORE sequence in the inotify buffer for the very same directory. To really force that in a non-stochastic way I'd need to mock events in this particular order, as the IN_DELETE_SELF and IN_IGNORE are tied together by inotify, not by different commands.

The loop really created 30 IN_CREATE | IN_DIR and 30 IN_DELETE | IN_DIR InotifyEvent instances, besides the IN_DELETE_SELF ones, which are less than 30, perhaps because some were deleted before a new wd was assigned to them. The Pandora's box is: when testing for watchdog events, that's what happens:

E         Differing items:
E         {<class 'watchdog.events.DirDeletedEvent'>: 37} != {<class 'watchdog.events.DirDeletedEvent'>: 30}
E         {<class 'watchdog.events.DirCreatedEvent'>: 28} != {<class 'watchdog.events.DirCreatedEvent'>: 30}
E         {<class 'watchdog.events.DirModifiedEvent'>: 55} != {<class 'watchdog.events.DirModifiedEvent'>: 60}

Testing again, it's clear that the numbers are random:

E         Differing items:
E         {<class 'watchdog.events.DirModifiedEvent'>: 51} != {<class 'watchdog.events.DirModifiedEvent'>: 60}
E         {<class 'watchdog.events.DirCreatedEvent'>: 26} != {<class 'watchdog.events.DirCreatedEvent'>: 30}
E         {<class 'watchdog.events.DirDeletedEvent'>: 43} != {<class 'watchdog.events.DirDeletedEvent'>: 30}

Actually, that's what I've got after implementing the straightforward solution for fixing this issue. I'm using tox -e py35 -- -k fast_sub to test based on #368.

danilobellini added a commit to danilobellini/watchdog that referenced this issue Sep 24, 2016
- 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)
danilobellini added a commit to danilobellini/watchdog that referenced this issue Sep 24, 2016
- 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
DonyorM pushed a commit that referenced this issue Oct 26, 2016
Inotify event order/duplication, fix #117 and #233
@DonyorM
Copy link
Contributor

DonyorM commented Oct 26, 2016

Fixed by #375.

@DonyorM DonyorM closed this as completed Oct 26, 2016
CCP-Aporia pushed a commit to CCP-Aporia/watchdog that referenced this issue Aug 13, 2020
- 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)
CCP-Aporia pushed a commit to CCP-Aporia/watchdog that referenced this issue Aug 13, 2020
- 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
CCP-Aporia pushed a commit to CCP-Aporia/watchdog that referenced this issue Aug 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants