You probably misunderstood me. You do not need to synchronize anything,
has been called. SNMP4J does not make an internal copy of the PDU
object for performance reasons. Thus, if you modify the object while
it is being send out, you get wrong results and BufferOverflowExceptions.
Thanks a lot Frank for information.
BTW, What is the fix here ?
Do I need to synchronize transport mapping only ?
Here is how I can create transport mapping.
private Snmp createSnmpSession (InetAddress address, int port)
throws IOException
{
s_logger.info ("Creating Snmp Session: " +
"addr = " + address + ", port = " + port);
TransportMapping transport = null;
if(address != null && port != -1)
{
transport = new DefaultUdpTransportMapping (
new UdpAddress (address, port));
}
else
{
transport = new DefaultUdpTransportMapping ();
}
// TODO - figure out how to use this properly - why are we
// doing this with only a pool size of one?
ThreadPool threadPool =
ThreadPool.create ("DispatcherPool", s_threadSize);
MessageDispatcher mtDispatcher = new MultiThreadedMessageDispatcher
(threadPool, new MessageDispatcherImpl ());
mtDispatcher.addMessageProcessingModel (new MPv1 ());
mtDispatcher.addMessageProcessingModel (new MPv2c ());
mtDispatcher.addMessageProcessingModel (s_mpv3);
Snmp snmp = new Snmp (mtDispatcher, transport);
return snmp;
}
--
With Thanks & Regards,
Akshay Ballarpure
AOffice: +91-40-4472-4112
-----Original Message-----
From: ext Frank Fock [mailto:fock at agentpp.com]
Sent: Wednesday, May 01, 2013 3:56 AM
To: Ballarpure, Akshay (NSN - IN/Hyderabad)
Cc: snmp4j at agentpp.org
Subject: Re: [SNMP4J] SNMP Buffer OverFlow Exception
Hello Akshay,
I think the root cause is the buffer overflow exception.
First, you should fix that issue.
1. The PDU or any contained VariableBinding is modified by another
thread (for example the PDU sender) after calling asynchronous
Snmp.send*.
2. A variable binding is being sent, that is not supported by the
protocol version (as you send a scoped pdu, I think this cases is not
matching your case).
Then you can optimize the threading behavior by reducing the
bootle neck in Snmp.NotificationDispatcher.processPdu by
public void processPdu(CommandResponderEvent event) {
CommandResponder listener;
synchronized (this) {
listener = notificationTransports.get(event.getTransportMapping());
}
if ((event.getPDU() != null) &&
(event.getPDU().getType() == PDU.INFORM)) {
// try to send INFORM response
try {
sendInformResponse(event);
}
catch (MessageException mex) {
if (logger.isWarnEnabled()) {
logger.warn("Failed to send response on INFORM PDU event (" +
event + "): " + mex.getMessage());
}
}
}
if (listener != null) {
listener.processPdu(event);
}
}
Best regards,
Frank
Hello Frank,
I am also facing below error in our application with SNMP4J stack (version is 1.11.1)
INFO | jvm 2 | 2013/04/29 13:36:54 | Exception in thread "Timer-7" java.nio.BufferOverflowException
INFO | jvm 2 | 2013/04/29 13:36:54 | at java.nio.Buffer.nextPutIndex(Unknown Source)
INFO | jvm 2 | 2013/04/29 13:36:54 | at java.nio.HeapByteBuffer.put(Unknown Source)
INFO | jvm 2 | 2013/04/29 13:36:54 | at org.snmp4j.asn1.BEROutputStream.write(BEROutputStream.java:64)
INFO | jvm 2 | 2013/04/29 13:36:54 | at org.snmp4j.asn1.BER.encodeHeader(BER.java:119)
INFO | jvm 2 | 2013/04/29 13:36:54 | at org.snmp4j.smi.VariableBinding.encodeBER(VariableBinding.java:178)
INFO | jvm 2 | 2013/04/29 13:36:54 | at org.snmp4j.PDU.encodeBER(PDU.java:528)
INFO | jvm 2 | 2013/04/29 13:36:54 | at org.snmp4j.ScopedPDU.encodeBER(ScopedPDU.java:123)
INFO | jvm 2 | 2013/04/29 13:36:54 | at org.snmp4j.mp.MPv3.prepareOutgoingMessage(MPv3.java:722)
INFO | jvm 2 | 2013/04/29 13:36:54 | at org.snmp4j.MessageDispatcherImpl.sendPdu(MessageDispatcherImpl.java:444)
INFO | jvm 2 | 2013/04/29 13:36:54 | at org.snmp4j.util.MultiThreadedMessageDispatcher.sendPdu(MultiThreadedMessageDispatcher.java:146)
INFO | jvm 2 | 2013/04/29 13:36:54 | at org.snmp4j.Snmp.sendMessage(Snmp.java:1067)
INFO | jvm 2 | 2013/04/29 13:36:54 | at org.snmp4j.Snmp$PendingRequest.run(Snmp.java:1610)
INFO | jvm 2 | 2013/04/29 13:36:54 | at java.util.TimerThread.mainLoop(Unknown Source)
INFO | jvm 2 | 2013/04/29 13:36:54 | at java.util.TimerThread.run(Unknown Source)
I took a thread dump and observed that all the dispatcher pool threads are in blocked state and hence SNMP4J stack is unable to process informs. So could you please let us know if it is known issue in SNMP4J stack version 1.11.1 ?
Thread dump from our apps
-------------------------------------------
"DispatcherPool.6" prio=3 tid=0x00a78c00 nid=0xe8 waiting for monitor entry [0x27e0f000]
java.lang.Thread.State: BLOCKED (on object monitor)
at org.snmp4j.Snmp$NotificationDispatcher.processPdu(Snmp.java:1825)
- waiting to lock <0x44c7c3d8> (a org.snmp4j.Snmp$NotificationDispatcher)
at org.snmp4j.Snmp.fireProcessPdu(Snmp.java:1430)
at org.snmp4j.Snmp.processPdu(Snmp.java:1288)
at org.snmp4j.MessageDispatcherImpl.fireProcessPdu(MessageDispatcherImpl.java:616)
at org.snmp4j.MessageDispatcherImpl.dispatchMessage(MessageDispatcherImpl.java:287)
at org.snmp4j.MessageDispatcherImpl.processMessage(MessageDispatcherImpl.java:347)
at org.snmp4j.util.MultiThreadedMessageDispatcher$MessageTask.run(MultiThreadedMessageDispatcher.java:209)
at org.snmp4j.util.ThreadPool$TaskManager.run(ThreadPool.java:239) - locked <
0x44cb3710> (a org.snmp4j.util.ThreadPool$TaskManager)
--
With Thanks & Regards,
Akshay Ballarpure
AOffice: +91-40-4472-4112
-----Original Message-----
From: snmp4j-bounces at agentpp.org [mailto:snmp4j-bounces at agentpp.org] On Behalf Of ext Frank Fock
Sent: Saturday, November 19, 2011 2:20 AM
To: snmp4j at agentpp.org
Subject: Re: [SNMP4J] SNMP Buffer OverFlow Exception
Hi Vinod,
You do not have to change anything on OS level.
With SNMP you cannot send packets that exceed 64K.
But I do not think that this is the problem here.
I guess that you modify the PDU contents while it
is being encoded. Have you checked that already?
Best regards,
Frank
Post by vinodHi,
I am facing the Buffer OverFlow Exception when trying to do send a snmp
packet. The Stack Trace is given below.
java.nio.BufferOverflowException
at java.nio.Buffer.nextPutIndex(Buffer.java:513)
at java.nio.HeapByteBuffer.put(HeapByteBuffer.java:163)
at org.snmp4j.asn1.BEROutputStream.write(BEROutputStream.java:64)
at org.snmp4j.asn1.BER.encodeHeader(BER.java:119)
at org.snmp4j.smi.Null.encodeBER(Null.java:99)
at
org.snmp4j.smi.VariableBinding.encodeBER(VariableBinding.java:181)
at org.snmp4j.PDU.encodeBER(PDU.java:528)
at org.snmp4j.mp.MPv1.prepareOutgoingMessage(MPv1.java:132)
at
org.snmp4j.MessageDispatcherImpl.sendPdu(MessageDispatcherImpl.java:444)
I had increased all the memory limits in linux and still facing this
problem very often. Kindly guide me in solving the problem.
Thanks,
Vinod Kumar Boppanna
_______________________________________________
SNMP4J mailing list
SNMP4J at agentpp.org
http://lists.agentpp.org/mailman/listinfo/snmp4j