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:
ProofOfConcept 2026-04-03 20:47:57 -04:00
parent 9c6aa69602
commit 2208e68b4f

View file

@ -305,10 +305,11 @@ async fn subscribe_one_daemon(
// ── One-shot queries ────────────────────────────────────────────
/// 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 {
Ok(s) => s,
Err(_) => return Vec::new(),
Err(_) => return None,
};
let (reader, writer) = stream.compat().split();
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();
result
Some(result)
}
/// Fetch channel status from all daemon sockets.
@ -387,13 +388,19 @@ async fn fetch_all_channels_inner() -> Vec<(String, bool, u32)> {
continue;
}
let sock = channels_dir.join(format!("{}.sock", daemon_name));
let channels = query_one_daemon(&sock).await;
if channels.is_empty() {
// Daemon is running but has no channels yet (e.g. telegram with no messages)
match query_one_daemon(&sock).await {
None => {
// Connection failed despite socket existing
result.push((daemon_name, false, 0));
}
Some(channels) if channels.is_empty() => {
// Connected but no channels yet
result.push((daemon_name, true, 0));
} else {
}
Some(channels) => {
result.extend(channels);
}
}
}
result
}