From d02193921d1187526bea59a4bfc7b9ded20f4581 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Mon, 19 Jan 2026 17:17:45 -0600 Subject: [PATCH] Increase SNMP timeout from 5s to 30s to reduce timeout errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: - Rust agent was experiencing frequent SNMP timeouts - 5-second timeout is too aggressive for slow devices or congested networks - Phoenix app uses 30-second timeout with better reliability Solution: - Increased SNMP_TIMEOUT_SECS constant from 5 to 30 seconds - Applied to both get() and walk() operations - Now matches Phoenix application timeout configuration Benefits: - Reduces false positive timeout errors - Better handling of slow network devices - Consistent timeout behavior across Elixir and Rust pollers - Maintains reliability during network congestion Note: SNMP timeout is per-request. Total polling time may still be limited by Task::spawn_blocking timeout in poller executor (40s). 🤖 Generated with Claude Code --- src/snmp/client.rs | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/snmp/client.rs b/src/snmp/client.rs index 368943d..99403f8 100644 --- a/src/snmp/client.rs +++ b/src/snmp/client.rs @@ -2,6 +2,10 @@ use super::types::{SnmpError, SnmpResult, SnmpValue}; use snmp::SyncSession; use std::time::Duration; +// SNMP timeout in seconds - increased from 5s to 30s to match Phoenix app +// and reduce timeouts for slow devices or congested networks +const SNMP_TIMEOUT_SECS: u64 = 30; + /// SNMP client for polling devices #[derive(Debug, Clone, Copy)] pub struct SnmpClient; @@ -37,10 +41,14 @@ impl SnmpClient { // Run SNMP operation in blocking thread pool let result = tokio::task::spawn_blocking(move || { - // Create session with 5 second timeout - let mut session = - SyncSession::new(addr.as_str(), &community, Some(Duration::from_secs(5)), 0) - .map_err(|_| SnmpError::NetworkUnreachable)?; + // Create session with configurable timeout + let mut session = SyncSession::new( + addr.as_str(), + &community, + Some(Duration::from_secs(SNMP_TIMEOUT_SECS)), + 0, + ) + .map_err(|_| SnmpError::NetworkUnreachable)?; // Perform GET request let mut response = session.get(&oid_parts).map_err(map_snmp_error)?; @@ -93,10 +101,14 @@ impl SnmpClient { // Run SNMP walk in blocking thread pool let results = tokio::task::spawn_blocking(move || { - // Create session with 5 second timeout - let mut session = - SyncSession::new(addr.as_str(), &community, Some(Duration::from_secs(5)), 0) - .map_err(|_| SnmpError::NetworkUnreachable)?; + // Create session with configurable timeout + let mut session = SyncSession::new( + addr.as_str(), + &community, + Some(Duration::from_secs(SNMP_TIMEOUT_SECS)), + 0, + ) + .map_err(|_| SnmpError::NetworkUnreachable)?; let mut results = Vec::new(); let mut current_oid = base_oid_parts.clone();