[ 
https://issues.apache.org/jira/browse/CAMEL-26779?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Claus Ibsen resolved CAMEL-26779.
---------------------------------
    Resolution: Fixed

Fixed on main by https://github.com/apache/camel/pull/29474 (4.24.0) and 
backported to camel-4.22.x by https://github.com/apache/camel/pull/29502 
(4.22.3).

_Claude Code on behalf of davsclaus_

> camel-snmp - the consumer can run its first poll before it is started, and 
> fails with a NullPointerException
> ------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-26779
>                 URL: https://issues.apache.org/jira/browse/CAMEL-26779
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-snmp
>    Affects Versions: 4.22.1
>            Reporter: Salvatore Mongiardo
>            Assignee: Salvatore Mongiardo
>            Priority: Minor
>             Fix For: 4.22.3, 4.24.0
>
>
> SnmpOIDPoller.doStart() calls super.doStart() first. 
> ScheduledPollConsumer.doStart() schedules the poll task, and only afterwards 
> doStart() creates the Snmp instance, the USM, the target and (in 4.22.x) the 
> request PDU, and starts the transport listener.
> If this initialization is slow, the first scheduled poll runs in between and 
> finds the fields not yet set. In 4.22.x the poll fails with:
> {noformat}
> WARN SnmpOIDPoller : Failed polling endpoint: snmp://udp:<host>/<port>. Will 
> try again at next poll.
> Caused by: [java.lang.NullPointerException - Cannot invoke 
> "org.snmp4j.PDU.clear()" because "this.pdu" is null]
>     at 
> org.apache.camel.component.snmp.SnmpOIDPoller.poll(SnmpOIDPoller.java:103)
> {noformat}
> Observed with Camel 4.22.1 on Windows x86_64 and JDK 21, where the gap 
> between the route start and "Started OID poller" was about 17 seconds. It 
> happened in 3 of 3 runs.
> On main, poll() creates a new PDU for each poll (CAMEL-25924), so the PDU is 
> no longer null. The race remains for snmp and target, which are still created 
> after super.doStart() has scheduled the poll.
> The consumer recovers on the next poll cycle, but the first poll fails with a 
> WARN and the first expected message is delayed or lost.
> Proposed change: in SnmpOIDPoller.doStart(), initialize snmp, the USM, the 
> target and the transport first, call transport.listen(), and call 
> super.doStart() last. The scheduler then starts only when the consumer is 
> ready to poll.
> Fix for main and for camel-4.22.x.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to