Bug 58522 - concurrency problem corrupts WARDirContext.Entry children
concurrency problem corrupts WARDirContext.Entry children
Product: Tomcat 7
Classification: Unclassified
Component: Catalina
All All
: P2 normal (vote)
: ---
Assigned To: Tomcat Developers Mailing List
Depends on:
  Show dependency tree
Reported: 2015-10-22 19:54 UTC by Ryan Fong
Modified: 2015-10-23 18:40 UTC (History)
0 users

everything (55.71 KB, application/x-zip-compressed)
2015-10-22 20:09 UTC, Ryan Fong
Proposal (1.30 KB, patch)
2015-10-23 15:07 UTC, Violeta Georgieva
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ryan Fong 2015-10-22 19:54:03 UTC
We discovered a problem where calling ServletContext.getResourcePaths from a jsp may corrupt WARDirContext.Entry.children. The WARDirContext.list(Entry) method performs an Arrays.sort(children) call which is not thread-safe. Calling this from multiple request threads may result in the children array losing some entries and duplicating others.

When entries representing directories in the war are lost, Tomcat cannot load resources from there. Static resource requests result in http error code 404 and jsp compliation can throw JasperException when included files are not found.

We have seen this on CentOS 6.5 (and newer versions) with Tomcat 7.0.52 and Java 1.7.0_51.

The following are attached in the zip:
* Test case project which demonstrates this corruption. It usually requires multiple runs.
* A stack trace illustrating the problematic flow.
* A patch file for WARDirContext.java.
Comment 1 Ryan Fong 2015-10-22 20:09:55 UTC
Created attachment 33195 [details]
Comment 2 Violeta Georgieva 2015-10-23 15:07:07 UTC
Created attachment 33201 [details]


Can you test the different approach that I have.

I also do not like the idea that the original array is returned but I didn't tested the performance if I return a copy of the array.

Comment 3 Ryan Fong 2015-10-23 15:52:03 UTC
G'day, Violeta. Your proposal looks great. In fact, it will likely improve throughput since we only deploy the war once and your patch avoids unnecessary sorting on all subsequent calls. Thank you!
Comment 4 Violeta Georgieva 2015-10-23 18:40:47 UTC

The fix is provided in 7.0.x trunk and will be available in 7.0.66 onwards.