Remove Tailscale and connection type complexity
Some checks failed
Build and Release / build-and-release (push) Has been cancelled

Simplifies host connection configuration by removing tailscale_ip field,
connection_type preferences, and fallback retry logic. Now uses only the
ip field or hostname as fallback. Eliminates blocking TCP connectivity
tests that interfered with heartbeat processing.

This resolves intermittent host lost/found issues by removing the
connection retry timeouts that blocked the ZMQ message processing loop.
This commit is contained in:
2025-11-15 10:04:47 +01:00
parent 76b6e3373e
commit f635ba9c75
7 changed files with 69 additions and 114 deletions

View File

@@ -71,6 +71,12 @@ impl ZmqConsumer {
pub async fn connect_to_host(&mut self, hostname: &str, port: u16) -> Result<()> {
let address = format!("tcp://{}:{}", hostname, port);
// First test basic TCP connectivity to the port
if let Err(e) = self.test_tcp_connectivity(hostname, port).await {
error!("TCP connectivity test failed for {}: {}", address, e);
return Err(e);
}
match self.subscriber.connect(&address) {
Ok(()) => {
info!("Connected to agent at {}", address);
@@ -84,6 +90,26 @@ impl ZmqConsumer {
}
}
/// Test TCP connectivity to a host and port with timeout
async fn test_tcp_connectivity(&self, hostname: &str, port: u16) -> Result<()> {
let timeout = std::time::Duration::from_secs(3);
match tokio::time::timeout(timeout, tokio::net::TcpStream::connect((hostname, port))).await {
Ok(Ok(_stream)) => {
debug!("TCP connectivity test passed for {}:{}", hostname, port);
Ok(())
}
Ok(Err(e)) => {
debug!("TCP connectivity test failed for {}:{}: {}", hostname, port, e);
Err(anyhow::anyhow!("TCP connection failed: {}", e))
}
Err(_) => {
debug!("TCP connectivity test timed out for {}:{}", hostname, port);
Err(anyhow::anyhow!("TCP connection timed out"))
}
}
}
/// Connect to predefined hosts using their configuration
pub async fn connect_to_predefined_hosts(&mut self, hosts: &std::collections::HashMap<String, crate::config::HostDetails>) -> Result<()> {
let default_port = self.config.subscriber_ports[0];
@@ -104,27 +130,13 @@ impl ZmqConsumer {
Ok(())
}
/// Connect to a host using its configuration details with fallback support
/// Connect to a host using its configuration details
pub async fn connect_to_host_with_details(&mut self, hostname: &str, host_details: &crate::config::HostDetails, port: u16) -> Result<()> {
// Get primary connection IP
// Get primary connection IP only - no fallbacks
let primary_ip = host_details.get_connection_ip(hostname);
// Try primary connection
if let Ok(()) = self.connect_to_host(&primary_ip, port).await {
info!("Connected to {} via primary address: {}", hostname, primary_ip);
return Ok(());
}
// Try fallback IPs if primary fails
let fallbacks = host_details.get_fallback_ips(hostname);
for fallback_ip in fallbacks {
if let Ok(()) = self.connect_to_host(&fallback_ip, port).await {
info!("Connected to {} via fallback address: {}", hostname, fallback_ip);
return Ok(());
}
}
Err(anyhow::anyhow!("Failed to connect to {} using all available addresses", hostname))
// Connect directly without fallback attempts
self.connect_to_host(&primary_ip, port).await
}
/// Receive command output from any connected agent (non-blocking)