@@ -14,6 +14,16 @@ struct Gateway {
1414 client : reqwest:: Client ,
1515}
1616
17+ /// Until the kernel reports a mount, cancellation must also stop helper processes.
18+ struct MountStartup ( Option < rustix:: process:: Pid > ) ;
19+ impl Drop for MountStartup {
20+ fn drop ( & mut self ) {
21+ if let Some ( pid) = self . 0 {
22+ let _ = rustix:: process:: kill_process_group ( pid, rustix:: process:: Signal :: KILL ) ;
23+ }
24+ }
25+ }
26+
1727fn alias ( binding : & MountBinding ) -> String {
1828 format ! ( "drive-{}-{:x}" , binding. id, binding. generation)
1929}
@@ -97,24 +107,52 @@ impl Driver {
97107 if binding. access == AccessMode :: ReadOnly {
98108 command. args ( [ "-o" , "ro" ] ) ;
99109 }
100- // GeeseFS's parent exits after the child has mounted the directory.
101- let output = command
110+ // Keep the helper and its mounting subprocess in a private process group.
111+ // A denied macFUSE activation can leave both processes waiting indefinitely.
112+ let mut child = command
113+ . arg ( "-f" )
102114 . arg ( & bucket)
103115 . arg ( & binding. path )
104116 . stdin ( Stdio :: null ( ) )
105- . output ( )
106- . await
117+ . process_group ( 0 )
118+ . spawn ( )
107119 . map_err ( |e| Error :: new ( ErrorCode :: Io , format ! ( "start geesefs: {e}" ) ) ) ?;
108- if !output. status . success ( ) {
109- return Err ( Error :: new (
110- ErrorCode :: Io ,
111- format ! (
112- "GeeseFS mount failed ({}): {}" ,
113- output. status,
114- String :: from_utf8_lossy( & output. stderr) . trim( )
115- ) ,
116- ) ) ;
120+ let mut group = MountStartup (
121+ child
122+ . id ( )
123+ . and_then ( |id| rustix:: process:: Pid :: from_raw ( id as i32 ) ) ,
124+ ) ;
125+ let startup = tokio:: time:: timeout ( Duration :: from_secs ( 20 ) , async {
126+ loop {
127+ if let Some ( status) = child. try_wait ( ) ? {
128+ return Err ( Error :: new ( ErrorCode :: Io , format ! ( "GeeseFS exited before mounting (status {status}); check the FUSE driver and daemon log" ) ) ) ;
129+ }
130+ if mount_source ( & binding. path ) ?. as_deref ( ) == Some ( bucket. as_str ( ) ) {
131+ return Ok ( ( ) ) ;
132+ }
133+ tokio:: time:: sleep ( Duration :: from_millis ( 50 ) ) . await ;
134+ }
135+ } ) . await . unwrap_or_else ( |_| Err ( Error :: new ( ErrorCode :: Unavailable ,
136+ "GeeseFS mount timed out; check the system FUSE driver, mount permissions and daemon log" ) ) ) ;
137+ if let Err ( error) = startup {
138+ if child. id ( ) . is_none ( ) {
139+ group. 0 = None ;
140+ }
141+ drop ( group) ;
142+ let _ = child. wait ( ) . await ;
143+ if mount_source ( & binding. path ) ?. as_deref ( ) == Some ( bucket. as_str ( ) ) {
144+ detach ( & binding. path ) . await ?;
145+ }
146+ return Err ( error) ;
117147 }
148+ group. 0 = None ;
149+ tokio:: spawn ( async move {
150+ if let Ok ( status) = child. wait ( ) . await
151+ && !status. success ( )
152+ {
153+ tracing:: warn!( %bucket, %status, "GeeseFS stopped" ) ;
154+ }
155+ } ) ;
118156 Ok ( ( ) )
119157 }
120158
@@ -143,9 +181,11 @@ impl Driver {
143181 ) ) ;
144182 }
145183 let path = binding. path . clone ( ) ;
146- tokio:: task:: spawn_blocking ( move || std:: fs:: File :: open ( path) ?. sync_all ( ) )
147- . await
148- . map_err ( |e| Error :: new ( ErrorCode :: Io , e. to_string ( ) ) ) ??;
184+ tokio:: task:: spawn_blocking ( move || -> std:: io:: Result < ( ) > {
185+ Ok ( rustix:: fs:: fsync ( std:: fs:: File :: open ( path) ?) ?)
186+ } )
187+ . await
188+ . map_err ( |e| Error :: new ( ErrorCode :: Io , e. to_string ( ) ) ) ??;
149189 Ok ( ( ) )
150190 }
151191
0 commit comments