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. |
| 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.
Is it required to remove that line?
There was a problem hiding this comment.
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.unschedulewith the following flow:/proc/pid/root/...),docker rm -f ..)After some debugging I noticed that the
InotifyBufferthread 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_watchis called after the thread stop event is set, which then generates an inotify event that causesos.readto return, and eventually the thread to finish its execution (aftershould_keep_runningreturns false). Otherwise, if the watch folder is deleted, anIN_DELETE_SELFevent is generated which causes the thread to stop (by settingdeleted_self).However, if the entire filesystem containing the watched object was unmounted, an
IN_UNMOUNTevent is generated, which isn't handled the same way (or at all). Additionally, in all these cases, anIN_IGNOREDevent should follow, which is what I ended up handling instead of the specificIN_UNMOUNT.All I did is set
deleted_selfif anIN_IGNOREDevent was received with the Inotify's path, to make sure the thread doesn't hang on the nextos.readcall, and it seem to have fixed the issue.TL;DR
Observer.unschedulehangs if scheduled on a folder in a removed container. I added handling ofIN_IGNOREDevents which should stop the thread on such cases.