Skip to content

Commit 2dda99b

Browse files
committed
Bugfix: mDNS resolved before discovery
- `on_host_resolved()` now creates the host entry when `ServiceResolved` arrives before `ServiceFound`, instead of dropping the resolution data with a warning - Adds `name` parameter to `on_host_resolved()` so late-created hosts get a proper display name - Fixes downstream SMB auth failures (`0xc000006d`) caused by hosts not being tracked in state
1 parent 4c9aadc commit 2dda99b

2 files changed

Lines changed: 29 additions & 18 deletions

File tree

apps/desktop/src-tauri/src/network/mdns_discovery.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ fn process_events(receiver: Receiver<ServiceEvent>) {
169169
id, hostname, ip_address, port
170170
);
171171

172-
on_host_resolved(&id, hostname, ip_address, port, &app_handle);
172+
on_host_resolved(&id, &name, hostname, ip_address, port, &app_handle);
173173
}
174174
ServiceEvent::ServiceRemoved(_, fullname) => {
175175
let name = extract_instance_name(&fullname);

apps/desktop/src-tauri/src/network/mod.rs

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ mod smb_types;
4040
mod smb_util;
4141

4242
use crate::ignore_poison::IgnorePoison;
43-
use log::{debug, warn};
43+
use log::debug;
4444
use serde::{Deserialize, Serialize};
4545
use std::collections::HashMap;
4646
use std::sync::{Mutex, OnceLock};
@@ -161,32 +161,43 @@ pub(crate) fn on_discovery_state_changed(new_state: DiscoveryState, app_handle:
161161
/// Called by the mDNS discovery module when a host's address is resolved.
162162
pub(crate) fn on_host_resolved(
163163
host_id: &str,
164+
name: &str,
164165
hostname: Option<String>,
165166
ip_address: Option<String>,
166167
port: u16,
167168
app_handle: &AppHandle,
168169
) {
169170
let mut state = get_discovery_state().lock_ignore_poison();
170171

171-
// Update the host with resolved info
172-
if let Some(host) = state.hosts.get_mut(host_id) {
173-
host.hostname = hostname.clone().or(host.hostname.clone());
174-
host.ip_address = ip_address.clone().or(host.ip_address.clone());
175-
host.port = port;
176-
172+
// If host wasn't seen via ServiceFound (race or library quirk), create it now
173+
if !state.hosts.contains_key(host_id) {
177174
debug!(
178-
"Host RESOLVED: id={}, hostname={:?}, ip={:?}, port={}",
179-
host_id, host.hostname, host.ip_address, port
180-
);
181-
182-
// Emit event to frontend with updated host info
183-
let _ = app_handle.emit("network-host-resolved", host.clone());
184-
} else {
185-
warn!(
186-
"Host RESOLVED but not found in state: id={}, hostname={:?}, ip={:?}",
187-
host_id, hostname, ip_address
175+
"Host RESOLVED before FOUND, creating entry: id={}, name={}, hostname={:?}, ip={:?}",
176+
host_id, name, hostname, ip_address
188177
);
178+
let host = NetworkHost {
179+
id: host_id.to_string(),
180+
name: name.to_string(),
181+
hostname: None,
182+
ip_address: None,
183+
port,
184+
};
185+
state.hosts.insert(host_id.to_string(), host.clone());
186+
let _ = app_handle.emit("network-host-found", &host);
189187
}
188+
189+
let host = state.hosts.get_mut(host_id).expect("just inserted or already present");
190+
host.hostname = hostname.clone().or(host.hostname.clone());
191+
host.ip_address = ip_address.clone().or(host.ip_address.clone());
192+
host.port = port;
193+
194+
debug!(
195+
"Host RESOLVED: id={}, hostname={:?}, ip={:?}, port={}",
196+
host_id, host.hostname, host.ip_address, port
197+
);
198+
199+
// Emit event to frontend with updated host info
200+
let _ = app_handle.emit("network-host-resolved", host.clone());
190201
}
191202

192203
/// Generates a stable ID from a service name.

0 commit comments

Comments
 (0)