hpcloud / tail

Go package for reading from continously updated files (tail -f)
MIT License
2.72k stars 505 forks source link

Fixes log reopening under inotify #115

Closed vladlosev closed 7 years ago

vladlosev commented 7 years ago

TL;DR this fixes a bug in fsnotify.Watch reference counting resulting in tail stopping updates after a tailed file is moved when using inotify.

When InotifyTracker.create is called from RemoveWatchCreate it decrements the watch counter for the parent dir of the filename tracked, then removes the watch and bails out. But the corresponding WatchCreate was incrementing counters for both tracked filename and its parent. Thus, the count for the filename is leaked. The following Create call would find the count for the filename already at 1 and assume the watch for the filename itself is already there. Thus no watch would be created and no updates would be coming.

This change moves the cleanup code into the single place and makes sure each InotifyTracker's RemoveWatch and RemoveWatchCreate calls correctly clean-up reference counts and watches created in corresponding Watch and WatchCreate calls. Also adds a couple of tests to verify the fix.

Nino-K commented 7 years ago

@vladlosev Thanks for your contribution.

vladlosev commented 7 years ago

Thank you! The build failures seem to be caused (from looking at the stack traces) by the bug fixed in fsnotify/fsnotify#203. Unfortunately, fsnotify/fsnotify haven't had a release after that PR, and the package at gopkg.in/fsnotify.v1 doesn't have any label to update to. 😞 Maybe switch to pulling fsnotify directly from github?