From 2208e68b4f3245aaab175f66614a85a74cb09caf Mon Sep 17 00:00:00 2001 From: ProofOfConcept Date: Fri, 3 Apr 2026 20:47:57 -0400 Subject: [PATCH] distinguish connection failure from empty channel list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/thalamus/channels.rs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/thalamus/channels.rs b/src/thalamus/channels.rs index 09b1d4f..4eaebfa 100644 --- a/src/thalamus/channels.rs +++ b/src/thalamus/channels.rs @@ -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> { 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,12 +388,18 @@ 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) - result.push((daemon_name, true, 0)); - } else { - result.extend(channels); + 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)); + } + Some(channels) => { + result.extend(channels); + } } } result