Bug 48901 - Endless wait by adding Synchronizing Timer
Summary: Endless wait by adding Synchronizing Timer
Status: RESOLVED FIXED
Alias: None
Product: JMeter - Now in Github
Classification: Unclassified
Component: HTTP (show other bugs)
Version: 2.3.2
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: JMeter issues mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-12 17:34 UTC by Cheng Chi
Modified: 2010-03-15 18:23 UTC (History)
0 users



Attachments
Stack trace of 100 threads which is performing endless wait (64.79 KB, application/octet-stream)
2010-03-12 17:36 UTC, Cheng Chi
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Cheng Chi 2010-03-12 17:34:59 UTC
All the threads will perform endless wait by adding Synchronizing Timer.

This issue is much easier reproduced under a heavy load. I was using 100 threads to a simple HTTP request sampler with adding a Synchronizing Timer, Groupsize set to 100 as well.

please see the attachment which is the stack trace of 100 threads doing a endless wait.

Some initial invstigation for this issue:

Here is the current source code:

public long delay() {
        synchronized (sync) {
            timerCounter[0]++;
            final int groupSz = getGroupSize();
            final int count = timerCounter[0];
            if (
                (groupSz == 0 && count >= JMeterContextService.getNumberOfThreads())
                ||
                (groupSz > 0 && count >= groupSz)
                ) {
                sync.notifyAll();
            } else {
                try {
                    sync.wait();
                } catch (InterruptedException e) {
                    log.warn(e.getLocalizedMessage());
                }
            }
            timerCounter[0]=0; // Reset for next time
        }
        return 0;
    }

The main problem from my perspective is after one thread call sync.notifyAll(); ,which means after the lock has been released,it will execute timerCounter[0]=0;(correct me if i am wrong)

After chaning the code as following(move "timerCounter[0]=0;" in front of "sync.notifyAll();", it does not impact any business impact, but make more sense to me), and the issue disappear:
public long delay() {
        synchronized (sync) {
            timerCounter[0]++;
            final int groupSz = getGroupSize();
            final int count = timerCounter[0];
            if (
                (groupSz == 0 && count >= JMeterContextService.getNumberOfThreads())
                ||
                (groupSz > 0 && count >= groupSz)
                ) {
                timerCounter[0]=0; // Reset for next time
                sync.notifyAll();
            } else {
                try {
                    sync.wait();
                } catch (InterruptedException e) {
                    log.warn(e.getLocalizedMessage());
                }
            }
        }
        return 0;
    }

Please review the code and make according changes with this issue. BTW,It can be reproduced on 2.3.4 release as well.
Hope this helps!
Comment 1 Cheng Chi 2010-03-12 17:36:44 UTC
Created attachment 25120 [details]
Stack trace of 100 threads which is performing endless wait
Comment 2 Sebb 2010-03-15 18:23:24 UTC
Thanks for the report and suggested fix.

Applied in SVN:

URL: http://svn.apache.org/viewvc?rev=923374&view=rev
Log:
Bug 48901 - Endless wait by adding Synchronizing Timer

Modified:
   jakarta/jmeter/trunk/src/components/org/apache/jmeter/timers/SyncTimer.java
   jakarta/jmeter/trunk/xdocs/changes.xml
Comment 3 The ASF infrastructure team 2022-09-24 20:37:44 UTC
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/2355