-
-
Notifications
You must be signed in to change notification settings - Fork 704
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
Fix Observer.unschedule
hang on linux when called with watch of an unmounted path
#869
Conversation
Thanks! Do you think writing a test case is possible for that? |
Done 🙂 |
@BoboTiG Changed the logic a bit to keep event reporting the same as it was before this change (so not adding any |
Sorry about the formatting issues, I fixed them and ran flake8 locally to make sure everything is formatted correctly |
Hey @BoboTiG, is there anything else you want me to do here? I don't think the failing tests are related to this PR - they are macos tests (which shouldn't be affected by my changes, since I only modified inotify), plus I saw the same tests failing on other (merged) PRs. Let me know if I'm missing something |
Sorry for the delay @IlayRosenberg, I'll review your PR shortly. |
@@ -323,7 +323,6 @@ def _recursive_simulate(src_path): | |||
path = self._path_for_wd.pop(wd) | |||
if self._wd_for_path[path] == wd: | |||
del self._wd_for_path[path] | |||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it required to remove that line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, because otherwise the IN_IGNORE
event isn't added to the event_list
and I can't handle it in InotifyBuffer.run
Hm I wanted to edit your changes, especially the changelog ones, but it is not allowed. Would you mind rebasing the PR on |
… as was done until now
I rebased and updated the changelog |
Thanks a lot @IlayRosenberg :) |
Description
I experienced a hang on
Observer.unschedule
with the following flow:/proc/pid/root/...
),docker rm -f ..
)After some debugging I noticed that the
InotifyBuffer
thread is stuck onInotify.read_events
, specifically onos.read(self._inotify_fd, event_buffer_size)
.As far as I can tell, usually when a watch is unscheduled,
inotify_rm_watch
is called after the thread stop event is set, which then generates an inotify event that causesos.read
to return, and eventually the thread to finish its execution (aftershould_keep_running
returns false). Otherwise, if the watch folder is deleted, anIN_DELETE_SELF
event is generated which causes the thread to stop (by settingdeleted_self
).However, if the entire filesystem containing the watched object was unmounted, an
IN_UNMOUNT
event is generated, which isn't handled the same way (or at all). Additionally, in all these cases, anIN_IGNORED
event should follow, which is what I ended up handling instead of the specificIN_UNMOUNT
.All I did is set
deleted_self
if anIN_IGNORED
event was received with the Inotify's path, to make sure the thread doesn't hang on the nextos.read
call, and it seem to have fixed the issue.TL;DR
Observer.unschedule
hangs if scheduled on a folder in a removed container. I added handling ofIN_IGNORED
events which should stop the thread on such cases.