directory-watcher icon indicating copy to clipboard operation
directory-watcher copied to clipboard

Duplicate events when editing file on Samba share

Open J-N-K opened this issue 2 years ago • 7 comments

We have found that sometimes editing files that are exposed on a samba share results in multiple create/delete events (up to six events in about half a second) instead of a single modify event.

We have now implemented a workaround in our code (https://github.com/openhab/openhab-core/pull/3404) but it would be great if this could be handled here as I believe it'll be encountered by a larger audience.

J-N-K avatar Feb 26 '23 12:02 J-N-K

Are there specific types of edits that cause that behavior? Did you check if it's the underlying Java watch service that's duplicating the events or if they're generated by directory-watcher itself? (you should be able to see with debug logging enabled)

Depending on how the events are generated, we can probably detect that sequence of events in directory-watcher and compress them into a single MODIFY.

gmethvin avatar Feb 26 '23 21:02 gmethvin

You can see example here: https://github.com/openhab/openhab-core/issues/3400#issuecomment-1445500615 (except the last post from myself, that is a bug in our code).

J-N-K avatar Feb 27 '23 17:02 J-N-K

Which platforms have you tested on? Seems like it's either due to a bug in the underlying WatchService implementation or the events the OS itself is reporting.

gmethvin avatar Feb 28 '23 10:02 gmethvin

For @mhilbush it is Ubuntu 22.04 for the samba server and a MacOS client. I'm not sure who actually is the issue here, if it's a faulty behavior of the client or the server.

J-N-K avatar Feb 28 '23 10:02 J-N-K

I also see similar behavior using a Windows client (e.g. Notepad++ on Win 10) and a Linux client (nano on Ubuntu) accessing the same share as with the MacOS client.

2023-02-28 07:18:03.876 [DEBUG] [io.methvin.watcher.DirectoryWatcher ] - ENTRY_MODIFY [/opt/openhab4/conf/rules/zoneminder.rules]
2023-02-28 07:18:03.877 [DEBUG] [io.methvin.watcher.DirectoryWatcher ] - -> MODIFY [/opt/openhab4/conf/rules/zoneminder.rules] (isDirectory: false)
2023-02-28 07:18:03.877 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'zoneminder.rules'
2023-02-28 07:18:03.923 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'zoneminder.rules' is either empty or cannot be parsed correctly!
2023-02-28 07:18:03.923 [DEBUG] [io.methvin.watcher.DirectoryWatcher ] - ENTRY_MODIFY [/opt/openhab4/conf/rules/zoneminder.rules]
2023-02-28 07:18:03.924 [DEBUG] [io.methvin.watcher.DirectoryWatcher ] - -> MODIFY [/opt/openhab4/conf/rules/zoneminder.rules] (isDirectory: false)
2023-02-28 07:18:03.924 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'zoneminder.rules'

Versus saving it locally using e.g. nano.

[2023-02-28 07:39:28.275 [DEBUG] [io.methvin.watcher.DirectoryWatcher ] - ENTRY_MODIFY [/opt/openhab4/conf/rules/zoneminder.rules]
2023-02-28 07:39:28.276 [DEBUG] [io.methvin.watcher.DirectoryWatcher ] - -> MODIFY [/opt/openhab4/conf/rules/zoneminder.rules] (isDirectory: false)
2023-02-28 07:39:28.277 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'zoneminder.rules'
2023-02-28 07:39:29.909 [DEBUG] [io.methvin.watcher.DirectoryWatcher ] - ENTRY_MODIFY [/opt/openhab4/conf/rules/zoneminder.rules]

mhilbush avatar Feb 28 '23 12:02 mhilbush

I am also getting 8 events on one event type . Like a file is deleted then 8 events are fired for it

priyankadhiman0803 avatar Jun 14 '23 15:06 priyankadhiman0803

I likely won't have time to look into this further anytime soon, but I'm happy to accept pull requests if anyone finds a viable way to handle this.

gmethvin avatar Jul 15 '23 10:07 gmethvin