Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.

Bug 1091215

Summary: Exception thrown from applications requestInitialized ServletRequestListener causes skipping requestDestroyed listeners, causing inconsistent state in Weld
Product: [JBoss] JBoss Enterprise Application Platform 6 Reporter: Marek Schmidt <maschmid>
Component: WebAssignee: Rémy Maucherat <rmaucher>
Status: CLOSED EOL QA Contact: Michael Cada <mcada>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 6.3.0CC: myarboro, pslavice
Target Milestone: ---   
Target Release: EAP 6.4.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-08-19 12:46:45 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
reproducer
none
reproducer source none

Description Marek Schmidt 2014-04-25 08:38:38 UTC
Created attachment 889561 [details]
reproducer

Description of problem:

Weld associates contexts with requests in its WeldListener. If an application contains its own buggy ServletRequestListener which throws exception, the thread will not disassociate the contexts from the thread, as WeldListener requestDestroyed will not be called.

This may cause weird problems when such broken thread eventually handles a different request, such as accessing different user's session. 

Version-Release number of selected component (if applicable):
6.3.0.ER2 (likely all EAP 6.x versions)

How reproducible:
Hardly

Steps to Reproduce:
1. Setup an executor with a single thread to make this problem easily reproducible, e.g.:

<subsystem xmlns="urn:jboss:domain:threads:1.1">
            <bounded-queue-thread-pool name="http-executor">
                <core-threads count="1"/>
                <queue-length count="1"/>
                <max-threads count="1"/>
                <keepalive-time time="10" unit="seconds"/>
            </bounded-queue-thread-pool>
        </subsystem>


<connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http" executor="http-executor"/>

2. Deploy the attached reproducer
3. Open two browsers (two user sessions), e.g. Firefox and Chrome:

firefox: open 
http://127.0.0.1:8080/jboss-as-helloworld/Login?id=foo

chrome: open
http://127.0.0.1:8080/jboss-as-helloworld/Login?id=bar

chrome: open
http://127.0.0.1:8080/jboss-as-helloworld/Fail

(this will result in an expected HTTP 500 error)

firefox: open 
http://127.0.0.1:8080/jboss-as-helloworld/HelloWorld

Actual results:
Page will say "Hello bar"

Expected results:
Page should say "Hello foo"

Additional info:

Doesn't seem to be a problem on Undertow on current Wildfly 7.1.0.CR1.

Comment 1 Marek Schmidt 2014-04-25 08:39:36 UTC
Created attachment 889562 [details]
reproducer source

Comment 2 Martin Velas 2014-08-04 12:20:37 UTC
Issue still persists in EAP 6.3.0.ER10.

Comment 3 Rémy Maucherat 2014-09-03 14:19:11 UTC
This looks like an invalid requirement to me, there's no provision indicating that requestDestroyed is supposed to be called in this situation.

Actually, it is the opposite, the section 11.6 on listener exceptions from the servlet spec indicates the listener must deal with it:
"Some exceptions do not occur under the call stack of another component in the
application. An example of this is a SessionListener that receives a notification
that a session has timed out and throws an unhandled exception, or of a
ServletContextListener that throws an unhandled exception during a notification of servlet context initialization, or of a ServletRequestListener that throws an unhandled exception during a notification of the initialization or the
destruction of the request object. In this case, the Developer has no opportunity to
handle the exception. The container may respond to all subsequent requests to the
Web application with an HTTP status code 500 to indicate an application error.

Developers wishing normal processing to occur after a listener generates an
exception must handle their own exceptions within the notification methods."

So the question is if you'd like to request optional proprietary behavior to be implemented.