Skip to content

Commit af2967a

Browse files
muirdmfacebook-github-bot
authored andcommitted
fix subscriber error detection
Summary: Use `select!` to detect if _either_ the tcpreceiver or subscriber tasks unexpectedly finishes. Previously we would first wait for the tcpreceiver task, which would block forever even if the workspacesubscriber task had exitted unexpectedly. I noticed my scm_daemon was not updating subscriptions properly when I changed workspace. The log file suggested the subscriber wasn't running at all, and this is my best guess how that can happen. Reviewed By: zzl0 Differential Revision: D68033878 fbshipit-source-id: 3933b7392d6e95ded8c9f66c29359123b380fd2a
1 parent 134a06d commit af2967a

File tree

1 file changed

+13
-12
lines changed
  • eden/scm/exec/scm_daemon/src

1 file changed

+13
-12
lines changed

eden/scm/exec/scm_daemon/src/main.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ use std::io::Read;
1212
#[cfg(target_os = "macos")]
1313
use std::io::Write;
1414

15+
use anyhow::anyhow;
1516
use anyhow::bail;
17+
use anyhow::Context;
1618
use anyhow::Result;
1719
use clap::App;
1820
use clap::Arg;
@@ -92,18 +94,17 @@ async fn main() -> Result<()> {
9294
let commitcloud_tcpreceiver_handler = commitcloud_tcpreceiver.serve();
9395
let commitcloud_workspacesubscriber_handler = commitcloud_workspacesubscriber.serve()?;
9496

95-
// join running services, this will block
96-
match commitcloud_tcpreceiver_handler.await {
97-
Ok(result) => result?,
98-
Err(_) => bail!("commitcloud tcpreceiver panicked"),
99-
};
100-
101-
match commitcloud_workspacesubscriber_handler.await {
102-
Ok(result) => result?,
103-
Err(_) => bail!("commitcloud workspace subscriber panicked"),
104-
};
105-
106-
Ok(())
97+
// Block until either service errors out.
98+
tokio::select! {
99+
result = commitcloud_tcpreceiver_handler => {
100+
result?.and_then(|_| Err(anyhow!("unexpected Ok() exit")))
101+
.context("commitcloud tcpreceiver")
102+
}
103+
result = commitcloud_workspacesubscriber_handler => {
104+
result?.and_then(|_| Err(anyhow!("unexpected Ok() exit")))
105+
.context("commitcloud workspace subscriber")
106+
}
107+
}
107108
}
108109

109110
/// Refuse to run if nice is too high (i.e. process has low priority)

0 commit comments

Comments
 (0)