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:
parent
d132f03d8b
commit
d02193921d
1 changed files with 20 additions and 8 deletions
|
|
@ -2,6 +2,10 @@ use super::types::{SnmpError, SnmpResult, SnmpValue};
|
||||||
use snmp::SyncSession;
|
use snmp::SyncSession;
|
||||||
use std::time::Duration;
|
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
|
/// SNMP client for polling devices
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct SnmpClient;
|
pub struct SnmpClient;
|
||||||
|
|
@ -37,10 +41,14 @@ impl SnmpClient {
|
||||||
|
|
||||||
// Run SNMP operation in blocking thread pool
|
// Run SNMP operation in blocking thread pool
|
||||||
let result = tokio::task::spawn_blocking(move || {
|
let result = tokio::task::spawn_blocking(move || {
|
||||||
// Create session with 5 second timeout
|
// Create session with configurable timeout
|
||||||
let mut session =
|
let mut session = SyncSession::new(
|
||||||
SyncSession::new(addr.as_str(), &community, Some(Duration::from_secs(5)), 0)
|
addr.as_str(),
|
||||||
.map_err(|_| SnmpError::NetworkUnreachable)?;
|
&community,
|
||||||
|
Some(Duration::from_secs(SNMP_TIMEOUT_SECS)),
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
.map_err(|_| SnmpError::NetworkUnreachable)?;
|
||||||
|
|
||||||
// Perform GET request
|
// Perform GET request
|
||||||
let mut response = session.get(&oid_parts).map_err(map_snmp_error)?;
|
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
|
// Run SNMP walk in blocking thread pool
|
||||||
let results = tokio::task::spawn_blocking(move || {
|
let results = tokio::task::spawn_blocking(move || {
|
||||||
// Create session with 5 second timeout
|
// Create session with configurable timeout
|
||||||
let mut session =
|
let mut session = SyncSession::new(
|
||||||
SyncSession::new(addr.as_str(), &community, Some(Duration::from_secs(5)), 0)
|
addr.as_str(),
|
||||||
.map_err(|_| SnmpError::NetworkUnreachable)?;
|
&community,
|
||||||
|
Some(Duration::from_secs(SNMP_TIMEOUT_SECS)),
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
.map_err(|_| SnmpError::NetworkUnreachable)?;
|
||||||
|
|
||||||
let mut results = Vec::new();
|
let mut results = Vec::new();
|
||||||
let mut current_oid = base_oid_parts.clone();
|
let mut current_oid = base_oid_parts.clone();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue