distinguish connection failure from empty channel list
query_one_daemon returns Option — None means connection failed, Some(vec![]) means connected but no channels yet. Fixes telegram showing as disconnected when it's running but has no messages. Co-Developed-By: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
9c6aa69602
commit
2208e68b4f
1 changed files with 16 additions and 9 deletions
|
|
@ -305,10 +305,11 @@ async fn subscribe_one_daemon(
|
||||||
// ── One-shot queries ────────────────────────────────────────────
|
// ── One-shot queries ────────────────────────────────────────────
|
||||||
|
|
||||||
/// One-shot query: connect to a daemon socket, call list(), return results.
|
/// One-shot query: connect to a daemon socket, call list(), return results.
|
||||||
async fn query_one_daemon(sock: &std::path::Path) -> Vec<(String, bool, u32)> {
|
/// Returns None if connection failed, Some(vec) if connected (possibly empty).
|
||||||
|
async fn query_one_daemon(sock: &std::path::Path) -> Option<Vec<(String, bool, u32)>> {
|
||||||
let stream = match UnixStream::connect(sock).await {
|
let stream = match UnixStream::connect(sock).await {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
Err(_) => return Vec::new(),
|
Err(_) => return None,
|
||||||
};
|
};
|
||||||
let (reader, writer) = stream.compat().split();
|
let (reader, writer) = stream.compat().split();
|
||||||
let rpc_network = Box::new(twoparty::VatNetwork::new(
|
let rpc_network = Box::new(twoparty::VatNetwork::new(
|
||||||
|
|
@ -343,7 +344,7 @@ async fn query_one_daemon(sock: &std::path::Path) -> Vec<(String, bool, u32)> {
|
||||||
}
|
}
|
||||||
|
|
||||||
rpc_handle.abort();
|
rpc_handle.abort();
|
||||||
result
|
Some(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch channel status from all daemon sockets.
|
/// Fetch channel status from all daemon sockets.
|
||||||
|
|
@ -387,12 +388,18 @@ async fn fetch_all_channels_inner() -> Vec<(String, bool, u32)> {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let sock = channels_dir.join(format!("{}.sock", daemon_name));
|
let sock = channels_dir.join(format!("{}.sock", daemon_name));
|
||||||
let channels = query_one_daemon(&sock).await;
|
match query_one_daemon(&sock).await {
|
||||||
if channels.is_empty() {
|
None => {
|
||||||
// Daemon is running but has no channels yet (e.g. telegram with no messages)
|
// Connection failed despite socket existing
|
||||||
result.push((daemon_name, true, 0));
|
result.push((daemon_name, false, 0));
|
||||||
} else {
|
}
|
||||||
result.extend(channels);
|
Some(channels) if channels.is_empty() => {
|
||||||
|
// Connected but no channels yet
|
||||||
|
result.push((daemon_name, true, 0));
|
||||||
|
}
|
||||||
|
Some(channels) => {
|
||||||
|
result.extend(channels);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result
|
result
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue