Increase SNMP timeout from 5s to 30s to reduce timeout errors

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
This commit is contained in:
Graham McIntire 2026-01-19 17:17:45 -06:00
parent d132f03d8b
commit d02193921d
No known key found for this signature in database

View file

@ -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();