[SNMP4J] HA: HA: [BugReport][SNMP4J-2.2.3] Concurrency bug in org.snmp4j.util.ThreadPool.

Frank Fock fock at agentpp.com
Thu Dec 18 21:34:39 CET 2014


Hi Dmitrii,

Yes, that is the root cause. I will fix it promptly.

Best regards,
Frank

Am 18.12.2014 21:31, schrieb Dmitrii Krendelev:
> The ptoblem is when the thread marked as interrupted, it does not release lock on wait(), but throw an InterruptedException immediately.
>
>
> Dmitrii Krendelev
> ________________________________________
> От: SNMP4J [snmp4j-bounces at agentpp.org] от имени Dmitrii Krendelev [krendelev at NetCracker.com]
> Отправлено: 18 декабря 2014 г. 23:22
> Кому: Frank Fock; snmp4j at agentpp.org
> Тема: [SNMP4J] HA: [BugReport][SNMP4J-2.2.3] Concurrency bug    in      org.snmp4j.util.ThreadPool.
>
> Hi, Frank,
>
> Thanks for answer!
>
>> ... if no TaskManager is there to handle the task.
> To become available, TaskManager need to execute section below
>
> synchronized (ThreadPool.this)
> {
>          this.task = null;
>          ThreadPool.this.notify();
> }
>
> But ThreadPool.this is blocked by  synchronized 'execute' method, so TaskManager-threads will never be available. And when we reach wait() method again, InterruptedException will be thrown again, so here is a cycle! We do not unlock the ThreadPool.this! (http://docs.oracle.com/javase/specs/jls/se7/html/jls-17.html ) This process will never stop since once we got an InterruptedException.
>
>
> Dmitrii Krendelev
>
> ________________________________________
> От: SNMP4J [snmp4j-bounces at agentpp.org] от имени Frank Fock [fock at agentpp.com]
> Отправлено: 18 декабря 2014 г. 22:43
> Кому: snmp4j at agentpp.org
> Тема: Re: [SNMP4J] [BugReport][SNMP4J-2.2.3] Concurrency bug in org.snmp4j.util.ThreadPool.
>
> Hi Dimitrii,
>
> When an InterruptedException is thrown in wait() it will be catched and
> a new interrupt()
> will be triggered. If not handled, the TaskManager continues in the loop
> but then finally
> calls wait() again, if no TaskManager is there to handle the task.
>
> I do not see any problem with the original code (which is different from
> what you quoted
> below).
>
> Best regards,
> Frank
>
> Am 18.12.2014 11:49, schrieb Dmitrii Krendelev:
>> 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.
>> _______________________________________________
>> SNMP4J mailing list
>> SNMP4J at agentpp.org
>> https://oosnmp.net/mailman/listinfo/snmp4j
> --
> ---
> AGENT++
> Maximilian-Kolbe-Str. 10
> 73257 Koengen, Germany
> https://agentpp.com
> Phone: +49 7024 8688230
> Fax:   +49 7024 8688231
>
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> https://oosnmp.net/mailman/listinfo/snmp4j
>
>
> ________________________________
> 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.
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> https://oosnmp.net/mailman/listinfo/snmp4j
>
>
> ________________________________
> 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.

-- 
---
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