[SNMP4J] HA: snmp4j for multiple device

Dmitrii Krendelev krendelev at NetCracker.com
Thu Dec 18 20:12:39 CET 2014


Hi,

The problem is not exactly about snmp protocol or how many devices we call in parallel. The problem is that org.snmp4j.util.ThreadPool.execute(WorkerTask task) method handle java.lang.InterruptedException in wrong way. Which lead the process to go in cycle and keep lock on ThreadPool object (because  'execute' method is synchronized). So, all the TaskManager-threads a blocked on object ThreadPool and never end.

To reproduce the problem it is important not only call enough devices to make all TaskManager threads busy, but also interrupt the main thread (which called 'execute' method). In order to demonstrate that snmp4j's handle java.lang.InterruptedException incorrectly, let me ask you to run the code below, which is exactly show what going on in 'execute' method when main thread is interupted. The thread goes in cycle.

/**
 * This class is demonstrated illegal way to handle InterruptedException
 * exactly like it is going on in org.snmp4j.util.ThreadPool.execute(WorkerTask task) method
 */
public class WrongInterruptDemo
{
        public static void main (String[] args)
        {
                final WrongInterruptDemo instance = new WrongInterruptDemo();

                Thread t = new Thread(new Runnable()
                {
                        public void run()
                        {
                                instance.execute();
                        }
                });

                t.start();
                t.interrupt();
        }

        private synchronized void execute()
        {
                while (true)
                {
                        try
                        {
                                System.out.println("before wait()");
                                wait();
                        }
                        catch (InterruptedException e)
                        {
                                Thread.currentThread().interrupt();
                        }
                }
        }
}


___________________________________________________________________________
Thanks,

Dmitrii Krendelev
___________________________________________________________________________





________________________________________
От: SNMP4J [snmp4j-bounces at agentpp.org] от имени Brijesh Kumar [brijeshvk at hotmail.com]
Отправлено: 18 декабря 2014 г. 20:10
Кому: SNMP4J at agentpp.org
Тема: [SNMP4J] snmp4j for multiple device

Hi,
I am running snmp4j request for 10 device parallel  . I am using snmpv3 . If all devices is having same set of cred set it works fine.
If any of this having different auth protocol (MD5 or SHA) or privacy protocol it fails .
I am getting below error
Message processing model 3 returned error: Unsupported security level

Is there any way i can accomplish sending multiple snmpv3 request to different device parallely ?

Regards
Brijesh

_______________________________________________
SNMP4J mailing list
SNMP4J at agentpp.org
https://oosnmp.net/mailman/listinfo/snmp4j





________________________________________________

From: Dmitrii Krendelev
Sent: Thursday, December 18, 2014 1:49 PM
To: 'support at snmp4j.org'; 'snmp4j at agentpp.org'
Subject: [BugReport][SNMP4J-2.2.3] Concurrency bug in org.snmp4j.util.ThreadPool.

Hi,

We have found quite a critical bug in org.snmp4j.util.ThreadPool.execute(WorkerTask task) method. It has an execute method below

    public synchronized void execute(WorkerTask task)
    {
        while (true)
        {
            // here we check if some TaskManager-thread is free to execute the task.
            try
            {
                wait(); // wait until some TaskManager-thread notify that it finished a previous task
            }
            catch (InterruptedException ex)
            {
                Thread.currentThread().interrupt();
            }
        }
     }

If  InterruptedException is thrown, so our thread goes into cycle and keep the lock on the ThreadPool object, so TaskManager-threads cannot notify that they became free as soon as they blocked on the ThreadPool. So if the interrupt was called when NO TaskManager-threads were free to execute the task, so the process just hangs.

There is a simple way to fix it. We need just to break the cycle if the process was interrupted and not to execute task like below.

    public synchronized void execute(WorkerTask task)
    {
       try
        {

           while (true)
           {
               // here we check if some TaskManager-thread is free to execute the task
               wait();// wait until some TaskManager-thread notify that it finished a previous task
           }
        catch (InterruptedException ex)
        {
           Thread.currentThread().interrupt();
        }

    }

Thanks,

Dmitrii Krendelev


________________________________
The information transmitted herein is intended only for the person or entity to which it is addressed and may contain confidential, proprietary and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.



More information about the SNMP4J mailing list