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

Fix inotify GC cleanup removing the watch function #4278

Merged
merged 2 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Fixed:
and `replaygain` metadata resolvers (#4245, fixed in #4246)
- Fixed source `last_metadata` not being properly updated (#4262)
- Convert all ICY (icecast) metadata from `input.http` to `utf8`.
- Fixed `inotify` unwatching due to GC cleanup (#4275)

---

Expand Down
21 changes: 8 additions & 13 deletions src/core/file_watcher.inotify.ml
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,12 @@ let watch : watch =
let e = List.flatten (List.map event_conv e) in
let wd = Inotify.add_watch fd file e in
handlers := (wd, f) :: !handlers;
let finalise fn = fn () in
let unwatch =
Mutex_utils.mutexify m (fun () ->
(try Inotify.rm_watch fd wd
with exn ->
let bt = Printexc.get_backtrace () in
Utils.log_exception ~log ~bt
(Printf.sprintf "Error whole removing file watch handler: %s"
(Printexc.to_string exn)));
handlers := List.remove_assoc wd !handlers)
in
Gc.finalise finalise unwatch;
unwatch)
Mutex_utils.mutexify m (fun () ->
(try Inotify.rm_watch fd wd
with exn ->
let bt = Printexc.get_backtrace () in
Utils.log_exception ~log ~bt
(Printf.sprintf "Error while removing file watch handler: %s"
(Printexc.to_string exn)));
handlers := List.remove_assoc wd !handlers))
()
Loading