[SNMP4J] java.nio.BufferOverflowException on 64-bit Windows 2008

Frank Fock fock at agentpp.com
Tue Nov 20 08:42:45 CET 2012


Hi,

Another tipp:

Use only a single Snmp instance. Otherwise you waste operating system
resources, because you allocate n-ports instead of one. Those ports
need to share the UDP buffer. As the buffer is fragmented by that, its
effective size will decrease significantly.

Best regards,
Frank


Am 20.11.2012 08:28, schrieb Frank Fock:
> Hi,
>
> This seems to be a Java bug rather than related to SNMP4J.
> What exact version are you using on the Windows 2008 64bit?
>
> One option might be to increase the UDP buffer on the OS level.
> It might also be that the Windows stops processing the buffer,
> but I guess the Java Runtime is throwing the exception
> although the full buffer error is no longer present (they forget
> to clear a error_no variable or something like that).
>
> Best regards,
> Frank
>
> Am 20.11.2012 06:48, schrieb Baskar Bharadwaj J:
>> Hi,
>> We get an exception in our multi-threaded application that uses SNMP4j
>> 2.0.3. Application sends get requests periodically to different agents
>> using SNMP4j, & suddenly the below exception arises (mostly between 30
>> min to 1 hr of starting the application). Once the below exception is
>> seen no further SNMP requests are getting processed (all requests fail
>> with the below exception).
>>
>> Below exception is peculiarly observed only in Windows 2008 64-bit
>> platform. Same runs well for days on Windows 7 32-bit platform.
>>
>> java.nio.BufferOverflowException
>>           at java.nio.Buffer.nextPutIndex(Unknown Source)
>>           at java.nio.HeapByteBuffer.put(Unknown Source)
>>           at org.snmp4j.asn1.BEROutputStream.write(BEROutputStream.java:63)
>>           at org.snmp4j.asn1.BER.encodeHeader(BER.java:118)
>>           at org.snmp4j.smi.Null.encodeBER(Null.java:95)
>>           at org.snmp4j.smi.VariableBinding.encodeBER(VariableBinding.java:180)
>>           at org.snmp4j.PDU.encodeBER(PDU.java:573)
>>           at org.snmp4j.mp.MPv1.prepareOutgoingMessage(MPv1.java:128)
>>           at org.snmp4j.MessageDispatcherImpl.sendPdu(MessageDispatcherImpl.java:472)
>>           at org.snmp4j.Snmp.sendMessage(Snmp.java:1005)
>>           at org.snmp4j.Snmp.send(Snmp.java:898)
>>           at org.snmp4j.Snmp.send(Snmp.java:878)
>>           at org.snmp4j.Snmp.send(Snmp.java:843)
>>           at org.snmp4j.Snmp.get(Snmp.java:555)
>>
>> Has anybody else come across this problem?
>>
>> Please share any pointers regarding the root cause of the observed
>> exception & possible way to resolve. Could this be an issue in
>> OpenNMS? or with the usage?
>>
>> Just to reproduce the problem, have isolated the SNMP4j usage from our
>> application & created a dummy multi-threaded application, which when
>> executed creates the problem with 30 min. Below is the source code of
>> the dummy application (always fails while encoding in Null.java,
>> line:95),
>>
>> package trial;
>> import java.io.IOException;
>> import java.util.Date;
>> import java.util.List;
>> import org.snmp4j.CommunityTarget;
>> import org.snmp4j.Snmp;
>> import org.snmp4j.mp.SnmpConstants;
>> import org.snmp4j.smi.Address;
>> import org.snmp4j.smi.GenericAddress;
>> import org.snmp4j.smi.OID;
>> import org.snmp4j.smi.OctetString;
>> import org.snmp4j.smi.VariableBinding;
>> import org.snmp4j.transport.DefaultUdpTransportMapping;
>> import org.snmp4j.util.DefaultPDUFactory;
>> import org.snmp4j.util.TreeEvent;
>> import org.snmp4j.util.TreeUtils;
>>
>> public class Trial1 {
>> public void snmpGetSubTreeMap(String strAddress, String community,
>> String strOID) {
>>
>> System.out.println("--------TIME:::::" + new Date() + " THREAD:"
>> + Thread.currentThread().getName());
>> Snmp snmp = null;
>>
>> try {
>> snmp = new Snmp(new DefaultUdpTransportMapping());
>> snmp.listen();
>> }
>> catch (IOException e) {
>> // TODO Auto-generated catch block
>> e.printStackTrace();
>> }
>>
>> try {
>> strAddress = strAddress + "/" + "161";
>> Address targetAddress = GenericAddress.parse(strAddress);
>> OctetString communityString = new OctetString(community);
>> CommunityTarget target = new CommunityTarget();
>> target.setCommunity(new OctetString(communityString));
>> target.setAddress(targetAddress);
>> target.setRetries(1);
>> target.setTimeout(1000);
>> target.setVersion(SnmpConstants.version1);
>>
>> TreeUtils tu = new TreeUtils(snmp, new DefaultPDUFactory());
>> String str = "";
>> //tu.setMaxRepetitions(10);
>>
>> List<TreeEvent> l = tu.getSubtree(target, new OID(strOID));
>> System.out.println("*_*_*_*_*_*_ TREE SIZE:" + l.size());
>>
>> if (l != null) {
>> for (TreeEvent treeEvent : l) {
>> if (treeEvent.getVariableBindings() != null) {
>> System.out.println("*_*_*_*_ TREE EVT:"+treeEvent);
>>
>> for (int i = 0; i < treeEvent.getVariableBindings().length; i++) {
>> VariableBinding vb = treeEvent.getVariableBindings()[i];
>> }
>> }
>> }
>> }
>> }
>> catch (Exception e) {
>> System.out.println("*_*_*_*_*_* EXCEPTION:::" + e);
>> e.printStackTrace();
>> }
>>
>> System.out.println("--------TIME:::::" + new Date() + " THREAD:" +
>> Thread.currentThread().getName());
>> }
>>
>> public static void main(String a[]) {
>> // new Task().start();
>> // new Task().start();
>> // new Task().start();
>> // new Task().start();
>> // new Task().start();
>> // new Task().start();
>> // new Task().start();
>> new Task().start();
>> new Task().start();
>> new Task().start();
>> new Task().start();
>> new Task().start();
>> }
>>
>> private static class Task extends Thread {
>> public void run() {
>> while (true) {
>> new Trial1().snmpGetSubTreeMap("10.20.4.3", "public", ".1.3.6.1.2.1.2.2.1.10");
>> new Trial1().snmpGetSubTreeMap("10.20.4.3", "public", ".1.3.6.1.2.1.2.2.1.16");
>> new Trial1().snmpGetSubTreeMap("10.20.4.3", "public", ".1.3.6.1.2.1.2.2.1.5");
>>
>> try {
>> Thread.sleep(5000);
>> }
>> catch (InterruptedException e) {
>> // TODO Auto-generated catch block
>> e.printStackTrace();
>> }
>> }
>> }
>> }
>> }
>>
>> Best Regards,
>> Baskar
>> _______________________________________________
>> SNMP4J mailing list
>> SNMP4J at agentpp.org
>> http://lists.agentpp.org/mailman/listinfo/snmp4j

-- 
---
AGENT++
Maximilian-Kolbe-Str. 10
73257 Koengen, Germany
https://agentpp.com
Phone: +49 7024 8688230
Fax:   +49 7024 8688231




More information about the SNMP4J mailing list