Bug 62662

Summary: Multithreaded JSP compilation generates invalid web.xml
Product: Tomcat 8 Reporter: Bernhard Frauendienst <apache>
Component: JasperAssignee: Tomcat Developers Mailing List <dev>
Severity: normal CC: emailgane
Priority: P2    
Version: 8.5.33   
Target Milestone: ----   
Hardware: PC   
OS: Linux   
Attachments: Patch to synchronize multi-threaded access to output streams

Description Bernhard Frauendienst 2018-08-30 14:52:24 UTC
The multi-threaded JSP compilation introduced in 8.5.33 with Bug 53492 can create race conditions that lead to invalid web.xml (fragments) to be generated. 

Since access of output streams in `generateWebMapping` is not thread-safe, this can cause mappings to be interleaved, like in this (real-life) example:

>    <servlet-mapping>
>        <servlet-name>org.apache.jsp.WEB_002dINF.jsp.admin.seoKeywordsCmsTable_jsp
>    <servlet-mapping>
>        <servlet-name></servlet-name>
>        <url-pattern>org.apache.jsp.WEB_002dINF.jsp.admin.seo.seokeywordtable_jsp</servlet-name>
>        <url-pattern>/WEB-INF/jsp/admin/seo/seoKeywordsCmsTable.jsp/WEB-INF/jsp/admin/seo/seokeywordtable.jsp</url-pattern>
>    </servlet-mapping>
>    </servlet-mapping>

Obviously, this causes an error on startup.
Comment 1 Bernhard Frauendienst 2018-08-30 16:12:32 UTC
Created attachment 36122 [details]
Patch to synchronize multi-threaded access to output streams

Attached patch should be sufficient to prevent chunks getting mixed up.
Comment 2 Mark Thomas 2018-08-31 10:06:10 UTC
Thanks for the patch.

Fixed in:
- trunk for 9.0.12 onwards
- 8.5.x for 8.5.34 onwards
- 7.0.x for 7.0.91 onwards
Comment 3 Mark Thomas 2018-09-05 08:38:56 UTC
*** Bug 62677 has been marked as a duplicate of this bug. ***