Skip to content

Commit

Permalink
fix subscriber error detection
Browse files Browse the repository at this point in the history
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
  • Loading branch information
muirdm authored and facebook-github-bot committed Jan 11, 2025
1 parent 134a06d commit af2967a
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions eden/scm/exec/scm_daemon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use std::io::Read;
#[cfg(target_os = "macos")]
use std::io::Write;

use anyhow::anyhow;
use anyhow::bail;
use anyhow::Context;
use anyhow::Result;
use clap::App;
use clap::Arg;
Expand Down Expand Up @@ -92,18 +94,17 @@ async fn main() -> Result<()> {
let commitcloud_tcpreceiver_handler = commitcloud_tcpreceiver.serve();
let commitcloud_workspacesubscriber_handler = commitcloud_workspacesubscriber.serve()?;

// join running services, this will block
match commitcloud_tcpreceiver_handler.await {
Ok(result) => result?,
Err(_) => bail!("commitcloud tcpreceiver panicked"),
};

match commitcloud_workspacesubscriber_handler.await {
Ok(result) => result?,
Err(_) => bail!("commitcloud workspace subscriber panicked"),
};

Ok(())
// Block until either service errors out.
tokio::select! {
result = commitcloud_tcpreceiver_handler => {
result?.and_then(|_| Err(anyhow!("unexpected Ok() exit")))
.context("commitcloud tcpreceiver")
}
result = commitcloud_workspacesubscriber_handler => {
result?.and_then(|_| Err(anyhow!("unexpected Ok() exit")))
.context("commitcloud workspace subscriber")
}
}
}

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

0 comments on commit af2967a

Please sign in to comment.