Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 314645 - XML Datasource is not Thread-Safe when passing data as InputStream
Summary: XML Datasource is not Thread-Safe when passing data as InputStream
Status: VERIFIED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: BIRT (show other bugs)
Version: 2.5.1   Edit
Hardware: PC Windows XP
: P3 critical with 4 votes (vote)
Target Milestone: 2.6.1   Edit
Assignee: Linda Chan CLA
QA Contact: Xiaoying Gu CLA
URL:
Whiteboard: Obsolete
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-27 08:56 EDT by simon.kuenzi CLA
Modified: 2010-08-06 05:15 EDT (History)
4 users (show)

See Also:


Attachments
Stacktrace (1.38 KB, text/plain)
2010-05-27 09:00 EDT, simon.kuenzi CLA
no flags Details
Sample Application (Testcase) (10.81 KB, application/octet-stream)
2010-05-27 09:06 EDT, simon.kuenzi CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description simon.kuenzi CLA 2010-05-27 08:56:40 EDT
Build Identifier: Eclipse Build id: 20090920-1017 / BIRT Runtime 2.5.1 + 2.5.2

When passing XML-data to the IRunTask in a multi-threaded application, some of the resulting .rptdocument files will be corrupted.

The error only occures when passing an InputStream using the setAppContext method:
ctxMap.put("org.eclipse.birt.report.data.oda.xml.inputStream", new FileInputStream("data.xml"));
ctxMap.put("org.eclipse.birt.report.data.oda.xml.closeInputStream", new Boolean(true));
task.setAppContext(ctxMap);

This warning will be written to the log: "WARNUNG: Exceptions occur during xml parsing" (see attachments for stackstrace)


Reproducible: Sometimes

Steps to Reproduce:
1. Run the sample application in the attachments (use the -Xmx1024m VM-Argument to avoid our of memory errors
2. Wait till the log shows the this warning: WARNUNG: Exceptions occur during xml parsing
3. Kill the sample application process
4. Analyze the generated rptdocument files (sort by ascending file size to find corrupted files)
Comment 1 simon.kuenzi CLA 2010-05-27 09:00:21 EDT
Created attachment 170172 [details]
Stacktrace
Comment 2 simon.kuenzi CLA 2010-05-27 09:06:40 EDT
Created attachment 170173 [details]
Sample Application (Testcase)

Sample Application that reproduces the bug in most of the cases.
Use the Xmx1024m VM-option to ovoid an out of memory error.
Comment 3 Wenjie Tu CLA 2010-07-30 02:37:50 EDT
Thanks for the simple but convinced test case, I reproduced it and finally found out the cause: 
In multihreading scenario, the appContext of one ODA connection may override the appContext of another ODA connection. need fix.

However, there's a minor issue in your test case code. Totally 500 tasks are runned in 500 threads and 500 BIRT document files should be outputted. But each time I run the code, only 49x(x=0,1...9) files are generated. It seems that UUID.randomUUID() is not threadsafe. If I put it into a static synchronized method like:
	private synchronized static UUID getUUID( )
	{
		 return UUID.randomUUID( );
	}
then the outputted files count is always 500.
Comment 4 Wenjie Tu CLA 2010-08-03 22:46:26 EDT
The problem is from odaconsumer, forward it to Linda.
Comment 5 Linda Chan CLA 2010-08-03 22:51:41 EDT
It now handles the use case when an appContext is passed in for an ODA connection.
Comment 6 Xiaoying Gu CLA 2010-08-06 05:15:37 EDT
Verified with daily build 2.6.1.v20100806-1040