Fix daemon autostart issue caused by sync pipewire retry loop (#43)

At boot time, PipeWire takes some time to register the `pwsp-daemon` and `pwsp-virtual-mic` devices. Previously, the daemon's retry loop for `link_player_to_virtual_mic()` was synchronous and limited to 5 attempts (1.5 seconds total). This caused systemd autostarts to fail with a code 1 if the devices were not yet available.

This change replaces the synchronous wait with an asynchronous `tokio::spawn` task. It will retry the link attempt up to 60 times with a 1-second delay without blocking the startup of the rest of the daemon. This prevents it from exiting abruptly during autostart.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
This commit is contained in:
Tarasov Aleksandr
2026-03-22 17:05:26 +03:00
committed by GitHub
parent 6114b9a7f8
commit f01a0e656c
5 changed files with 58 additions and 38 deletions
+17 -10
View File
@@ -31,16 +31,20 @@ async fn main() -> Result<(), Box<dyn Error>> {
eprintln!("Failed to initialize audio player: {}", err);
} // Initialize audio player
let max_retries = 5;
for i in 0..=max_retries {
match link_player_to_virtual_mic().await {
Ok(_) => break,
Err(e) => println!("{e}\t{i}/{max_retries}"),
}
tokio::spawn(async {
let max_retries = 60;
for i in 0..=max_retries {
match link_player_to_virtual_mic().await {
Ok(_) => {
println!("Successfully linked player to virtual mic.");
break;
}
Err(e) => println!("{e}\t{i}/{max_retries}"),
}
sleep(Duration::from_millis(300 * i)).await;
}
link_player_to_virtual_mic().await?;
sleep(Duration::from_millis(1000)).await;
}
});
let runtime_dir = get_runtime_dir();
@@ -97,7 +101,10 @@ async fn commands_loop(listener: UnixListener) -> Result<(), Box<dyn Error>> {
let request_len = u32::from_le_bytes(len_bytes) as usize;
if request_len > 10 * 1024 * 1024 {
eprintln!("Failed to read message from client: request too large ({} bytes)!", request_len);
eprintln!(
"Failed to read message from client: request too large ({} bytes)!",
request_len
);
return;
}