https://issues.apache.org/bugzilla/show_bug.cgi?id=48760

--- Comment #11 from Stefan Kendall <arcanef...@gmail.com> 2010-02-18 20:02:19 
UTC ---
gfuser9...@yahoo.co.uk has presented a reasoned explanation of what is
happening below. Apparently, this is a problem that needs to be backported from
Glassfish.

I've copied the e-mail below:

Now, really the REAL bug fix in Tomcat you need to port 
back from
 Glassfish is actually this 

http://fisheye5.cenqua.com/changelog/glassfish?cs=SJSAS91_FCS_BRANCH%3Asultal%3A20080904082511

This is the actual root cause for 45601 which is not
updated back to Tomcat bug entry in the late 2008 but 
this is the RCA and is fixed in SUN Glassfish Application
server (where they share the same common TC code).

--------------------------
Here's the salient point:
--------------------------
0. You notice the issue happens in DefaultServlet copyRange
   as all your submitters submit

- The code all do something like this
   InputStream resourceInputStream 
      = cacheEntry.resource.streamContent();

1. So they all take a FileResource/Resource from
   a cache entry  (which is looked up from some cache)

2. Now We know that this is a FileResource (static resource)

3. Finally most of the code will have this

   reader = new
 InputStreamReader(resourceInputStream,
                               fileEncoding);
   copyRange(reader,....) <-- do something
   reader.close();

4.
 Now, you notice that reader.close() will CLOSE
   the underlying FileInputStream when it is run.

5. Hence, there is a SUBTLE race in FileResource.streamContent
   where a TWO or more threads get the SAME InputStream.
   This is due to the FACT that multiple requests can
   get hold of the same cached entry and hence due to
   the BAD way the FileResource streamContent stuff the
   InputStream to a temp instance variable.. 

   Due to MT scheduling (it is possible to get a MT schedule
   where two threads gets the some common InputStream.)
   [Please see TC code to see why this can happen]

Testing?
------------
It is easy to ARTIFICIALLY reproduce & to confirm
You can slow things down in the
 FileResource.streamContent()
by putting delays and etc (or also printing
the resulting InputStream in the copy while
doing two or more parallel wget for the same
FileResource of filesize of some large MB to see.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to