[SNMP-2] ConcurrentModificationException warnings during walk, incomplete data retrieved Created: 01/Jul/15  Updated: 19/Oct/17  Resolved: 12/Jul/15

Status: Resolved
Project: snmp
Component/s: General
Affects Version/s: unspecified
Fix Version/s: None

Type: Bug
Reporter: Jon Rosenberger Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating System: All
Platform: All


Attachments: Text File file_3921.txt     File testWalkRemote.rtf    
External issue ID: 3921
Priority: High

 Description   

Calls to snmpGet with input type GETWALK return partial results when the result set is large enough. The problem is only seen in queries that require a number of seconds to execute.

No error is returned, but results are incomplete. Caller has no way to know they are incomplete. Logs contain many stack traces logged as WARN, below.

Attached test case reproduces the problem consistently. It connects to a real server. Any server/oid combination returning a sizable result set should suffice to reproduce this issue.

[Timer-0] WARN org.opendaylight.snmp.plugin.internal.AsyncGetHandler - Error parsing response
java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:859)
at java.util.ArrayList$Itr.next(ArrayList.java:831)
at org.opendaylight.snmp.plugin.internal.AsyncGetHandler.setResult(AsyncGetHandler.java:125)
at org.opendaylight.snmp.plugin.internal.AsyncGetHandler.onResponse(AsyncGetHandler.java:113)
at org.snmp4j.Snmp$PendingRequest.run(Snmp.java:1721)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)



 Comments   
Comment by Jon Rosenberger [ 01/Jul/15 ]

Attachment testWalkRemote.rtf has been added with description: test case to reproduce issue

Comment by Jon Rosenberger [ 01/Jul/15 ]

The problem: Everything works for several seconds, but then snmp4j begins sending response events to AsyncGetHandler.onResponse() containing null responses, immediately after requests are made. These are not timeouts; the correct data does arrive after several ms in a separate event as expected.

The issue is resolved by adding to the top of onResponse:

// acknowledge receipt of the event
Object source = responseEvent.getSource();
((Snmp)source).cancel(responseEvent.getRequest(), this);

which is recommended by the API docs:

public void onResponse(ResponseEvent event)

{ // Always cancel async request when response has been received // otherwise a memory leak is created! Not canceling a request // immediately can be useful when sending a request to a broadcast // address. ((Snmp)event.getSource()).cancel(event.getRequest(), this); System.out.println("Received response PDU is: "+event.getResponse()); }

see http://www.snmp4j.org/doc/org/snmp4j/Snmp.html

This causes the handler to call setResult. Events continue to arrive however, resulting in the ConcurrentModificationException.

Comment by Jon Rosenberger [ 01/Jul/15 ]

Attached patch resolves the issue. It also adds error logging so that the problem can be seen as it happens, rather than downstream (in this case the ConcurrentModificationException was not the root cause). This will help in other cases where the response is null (timeouts).

Comment by Jon Rosenberger [ 01/Jul/15 ]

Attachment file_3921.txt has been added with description: patch to resolve issue

Generated at Wed Feb 07 20:39:10 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.