File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ use crate::{
2727} ;
2828use crate :: { impl_on_click, impl_wrapper} ;
2929
30- use super :: Module ;
30+ use super :: { KillOnDrop , Module } ;
3131
3232#[ derive( Debug , Builder ) ]
3333pub struct MediaMod {
@@ -493,6 +493,10 @@ impl Module for MediaMod {
493493 . take ( )
494494 . expect ( "child did not have a handle to stdout" ) ;
495495
496+ // Kill playerctl when the subscription ends (e.g. on reload),
497+ // so it doesn't leak and accumulate processes.
498+ let _kill_on_drop = KillOnDrop ( child) ;
499+
496500 let mut reader = BufReader :: new ( stdout) . lines ( ) ;
497501 let mut last_track = String :: new ( ) ;
498502
Original file line number Diff line number Diff line change @@ -160,6 +160,17 @@ pub trait Module: Any + Debug + Send + Sync + Downcast {
160160}
161161impl_downcast ! ( Module ) ;
162162
163+ /// Kills the wrapped child process when dropped, so subscription child
164+ /// processes (e.g. `pactl subscribe`, `playerctl --follow`) don't leak when
165+ /// the subscription ends (e.g. on config reload).
166+ pub struct KillOnDrop ( pub tokio:: process:: Child ) ;
167+
168+ impl Drop for KillOnDrop {
169+ fn drop ( & mut self ) {
170+ let _ = self . 0 . start_kill ( ) ;
171+ }
172+ }
173+
163174pub trait Action : Any + Debug + Send + Sync + Downcast {
164175 fn as_message ( & self ) -> Message ;
165176}
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ use crate::{
2121} ;
2222use crate :: { impl_on_click, impl_wrapper} ;
2323
24- use super :: Module ;
24+ use super :: { KillOnDrop , Module } ;
2525
2626#[ derive( Default , Debug , Builder ) ]
2727pub struct VolumeMod {
@@ -109,6 +109,10 @@ impl Module for VolumeMod {
109109 . take ( )
110110 . expect ( "child did not have a handle to stdout" ) ;
111111
112+ // Kill pactl when the subscription ends (e.g. on reload), so
113+ // it doesn't leak and exhaust the pulse client limit.
114+ let _kill_on_drop = KillOnDrop ( child) ;
115+
112116 let mut reader = BufReader :: new ( stdout) . lines ( ) ;
113117
114118 while let Some ( line) = reader. next_line ( ) . await . unwrap ( ) {
You can’t perform that action at this time.
0 commit comments