Bug 60830 - Timestamps in CSV file could be corrupted due to sharing a SimpleDateFormatter across threads
Summary: Timestamps in CSV file could be corrupted due to sharing a SimpleDateFormatte...
Status: RESOLVED FIXED
Alias: None
Product: JMeter - Now in Github
Classification: Unclassified
Component: Main (show other bugs)
Version: 3.1
Hardware: All All
: P2 blocker (vote)
Target Milestone: ---
Assignee: JMeter issues mailing list
URL:
Keywords:
: 60818 (view as bug list)
Depends on:
Blocks:
 
Reported: 2017-03-07 19:37 UTC by eric.markowitz
Modified: 2017-03-26 20:01 UTC (History)
2 users (show)



Attachments
Patch that does not handle setLenient (7.54 KB, patch)
2017-03-07 22:02 UTC, Philippe Mouawad
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description eric.markowitz 2017-03-07 19:37:12 UTC
The java.text.SimpleDateFormatter class is not thread safe, but jmeter reuses a SimpleDateFormatter instance across threads.  As a result, the saved timestamp is sometimes incorrect.  Here is the stack trace of one of the offending locations: 

org.apache.jmeter.save.CSVSaveService.resultToDelimitedString(CSVSaveService.java:868)
org.apache.jmeter.save.CSVSaveService.resultToDelimitedString(CSVSaveService.java:784)
org.apache.jmeter.reporters.ResultCollector.sampleOccurred(ResultCollector.java:559)
org.apache.jmeter.threads.ListenerNotifier.notifyListeners(ListenerNotifier.java:67)
org.apache.jmeter.threads.JMeterThread.notifyListeners(JMeterThread.java:819)
org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:493)
org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:410)
org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:241)
java.lang.Thread.run(Thread.java:745)
Comment 1 Philippe Mouawad 2017-03-07 19:42:52 UTC
(In reply to eric.markowitz from comment #0)
> The java.text.SimpleDateFormatter class is not thread safe, but jmeter
> reuses a SimpleDateFormatter instance across threads.  As a result, the
> saved timestamp is sometimes incorrect.  Here is the stack trace of one of
> the offending locations: 
> 
> org.apache.jmeter.save.CSVSaveService.resultToDelimitedString(CSVSaveService.
> java:868)
> org.apache.jmeter.save.CSVSaveService.resultToDelimitedString(CSVSaveService.
> java:784)
> org.apache.jmeter.reporters.ResultCollector.sampleOccurred(ResultCollector.
> java:559)
> org.apache.jmeter.threads.ListenerNotifier.notifyListeners(ListenerNotifier.
> java:67)
> org.apache.jmeter.threads.JMeterThread.notifyListeners(JMeterThread.java:819)
> org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.
> java:493)
> org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:410)
> org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:241)
> java.lang.Thread.run(Thread.java:745)

Hello Eric,
Thanks for report, but where is the SimpleDateFormatter you mention ?
What version of JMeter are you using ?

Thanks
Comment 2 eric.markowitz 2017-03-07 19:46:44 UTC
I omitted some stack frames previously.  Here is the full stack:

        at java.text.SimpleDateFormat.format(SimpleDateFormat.java:971)
        at java.text.SimpleDateFormat.format(SimpleDateFormat.java:935)
        at java.text.DateFormat.format(DateFormat.java:345)
        at org.apache.jmeter.save.CSVSaveService.resultToDelimitedString(CSVSaveService.java:868)
        at org.apache.jmeter.save.CSVSaveService.resultToDelimitedString(CSVSaveService.java:784)
        at org.apache.jmeter.reporters.ResultCollector.sampleOccurred(ResultCollector.java:559)
        at org.apache.jmeter.threads.ListenerNotifier.notifyListeners(ListenerNotifier.java:67)
        at org.apache.jmeter.threads.JMeterThread.notifyListeners(JMeterThread.java:819)
        at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:493)
        at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:410)
        at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:241)
        at java.lang.Thread.run(Thread.java:745)

I noticed the problem in jmeter version3.
Comment 3 Philippe Mouawad 2017-03-07 21:11:49 UTC
Hi Team,
Could we use DateTimeFormatter to fix this issue ?

Instanciating a SimpleDateFormat for each call might be overkill.
Using ThreadLocal SimpleDateFormat is not simple here
Comment 4 Philippe Mouawad 2017-03-07 22:02:26 UTC
Created attachment 34806 [details]
Patch that does not handle setLenient
Comment 5 Philippe Mouawad 2017-03-08 20:40:18 UTC
*** Bug 60818 has been marked as a duplicate of this bug. ***
Comment 6 eric.markowitz 2017-03-08 22:19:05 UTC
I don't think Bug 60818 is a duplicate.  Bug 60818 refers to a corruption of the CSV file, while this bug referes to incorrect timestamps written to the CSV file.
Comment 7 Philippe Mouawad 2017-03-08 22:21:07 UTC
(In reply to eric.markowitz from comment #6)
> I don't think Bug 60818 is a duplicate.  Bug 60818 refers to a corruption of
> the CSV file, while this bug referes to incorrect timestamps written to the
> CSV file.

Hi,
The other bug is Invalid in fact. See related discussion.
But if there is a corruption, it's in the issue your raised.

Regards
Comment 8 Philippe Mouawad 2017-03-10 19:52:22 UTC
Hi,
Any feedback on patch ? Or alternative solution ?

I think we need to fix this bug before 3.2 .
Thanks
Comment 9 Philippe Mouawad 2017-03-18 10:13:00 UTC
Author: pmouawad
Date: Sat Mar 18 10:12:31 2017
New Revision: 1787542

URL: http://svn.apache.org/viewvc?rev=1787542&view=rev
Log:
Bug 60830 - Timestamps in CSV file could be corrupted due to sharing a SimpleDateFormatter across threads
Bugzilla Id: 60830

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleSaveConfiguration.java
    jmeter/trunk/src/core/org/apache/jmeter/save/CSVSaveService.java
    jmeter/trunk/test/src/org/apache/jmeter/samplers/TestSampleSaveConfiguration.java
    jmeter/trunk/xdocs/changes.xml
Comment 10 Philippe Mouawad 2017-03-26 20:01:37 UTC
Author: pmouawad
Date: Sun Mar 26 20:00:59 2017
New Revision: 1788774

URL: http://svn.apache.org/viewvc?rev=1788774&view=rev
Log:
Bug 60830 Timestamps in CSV file could be corrupted due to sharing a SimpleDateFormatter across threads
Bugzilla Id: 60830

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleSaveConfiguration.java
Comment 11 The ASF infrastructure team 2022-09-24 20:38:08 UTC
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/4322