@@ -53,6 +53,7 @@ use tokio::process::Child;
5353use tokio:: process:: Command ;
5454#[ cfg( feature = "packaged_rsync" ) ]
5555use tokio:: sync:: OnceCell ;
56+ use tracing:: warn;
5657
5758use crate :: code_sync:: WorkspaceLocation ;
5859
@@ -69,7 +70,7 @@ async fn get_rsync_bin_path() -> Result<&'static Path> {
6970 Ok ( RSYNC_BIN_PATH
7071 . get_or_try_init ( || async {
7172 tokio:: task:: spawn_blocking ( || {
72- let mut tmp = tempfile:: NamedTempFile :: new ( ) ?;
73+ let mut tmp = tempfile:: NamedTempFile :: with_prefix ( "rsync." ) ?;
7374 let rsync_bin = include_bytes ! ( "rsync.bin" ) ;
7475 tmp. write_all ( rsync_bin) ?;
7576 let bin_path = tmp. into_temp_path ( ) ;
@@ -239,7 +240,6 @@ pub async fn do_rsync(addr: &SocketAddr, workspace: &Path) -> Result<RsyncResult
239240#[ derive( Debug ) ]
240241pub struct RsyncDaemon {
241242 child : Child ,
242- #[ allow( unused) ]
243243 state : TempDir ,
244244 addr : SocketAddr ,
245245}
@@ -284,8 +284,7 @@ impl RsyncDaemon {
284284 . arg ( format ! ( "--address={}" , addr. ip( ) ) )
285285 . arg ( format ! ( "--port={}" , addr. port( ) ) )
286286 . arg ( format ! ( "--config={}" , config. display( ) ) )
287- //.arg(format!("--log-file={}/log", state.path().display()))
288- . arg ( "--log-file=/dev/stderr" )
287+ . arg ( format ! ( "--log-file={}/log" , state. path( ) . display( ) ) )
289288 . kill_on_drop ( true )
290289 . spawn ( ) ?;
291290
@@ -315,14 +314,15 @@ impl RsyncDaemon {
315314 & self . addr
316315 }
317316
318- pub async fn shutdown ( mut self ) -> Result < ( ) > {
317+ pub async fn shutdown ( mut self ) -> Result < String > {
318+ let logs = fs:: read_to_string ( self . state . path ( ) . join ( "log" ) ) . await ;
319319 let id = self . child . id ( ) . context ( "missing pid" ) ?;
320320 let pid = Pid :: from_raw ( id as i32 ) ;
321321 signal:: kill ( pid, Signal :: SIGINT ) ?;
322322 let status = self . child . wait ( ) . await ?;
323323 // rsync exists with 20 when sent SIGINT.
324324 ensure ! ( status. code( ) == Some ( 20 ) ) ;
325- Ok ( ( ) )
325+ Ok ( logs? )
326326 }
327327}
328328
@@ -412,7 +412,7 @@ where
412412 let instance = actor_mesh. proc_mesh ( ) . client ( ) ;
413413 let ( rsync_conns_tx, rsync_conns_rx) = instance. open_port :: < Connect > ( ) ;
414414
415- let ( ( ) , results ) = try_join ! (
415+ let res = try_join ! (
416416 rsync_conns_rx
417417 . take( actor_mesh. shape( ) . slice( ) . len( ) )
418418 . err_into:: <anyhow:: Error >( )
@@ -443,11 +443,25 @@ where
443443 . await ?;
444444 anyhow:: Ok ( res)
445445 } ,
446- ) ? ;
446+ ) ;
447447
448- daemon. shutdown ( ) . await ?;
448+ // Kill rsync server and attempt to grab the logs.
449+ let logs = daemon. shutdown ( ) . await ;
449450
450- Ok ( results)
451+ // Return results, attaching rsync daemon logs on error.
452+ match res {
453+ Ok ( ( ( ) , results) ) => {
454+ let _ = logs?;
455+ Ok ( results)
456+ }
457+ Err ( err) => match logs {
458+ Ok ( logs) => Err ( err) . with_context ( || format ! ( "rsync server logs: {}" , logs) ) ,
459+ Err ( shutdown_err) => {
460+ warn ! ( "failed to read logs from rsync daemon: {:?}" , shutdown_err) ;
461+ Err ( err)
462+ }
463+ } ,
464+ }
451465}
452466
453467#[ cfg( test) ]
0 commit comments