You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2012/05/31 19:06:36 UTC

[Bug 53337] New: IllegalStateException when trying to render a JSP after startAsync

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

          Priority: P2
            Bug ID: 53337
          Assignee: dev@tomcat.apache.org
           Summary: IllegalStateException when trying to render a JSP
                    after startAsync
          Severity: normal
    Classification: Unclassified
                OS: Linux
          Reporter: rstoyanchev@yahoo.com
          Hardware: PC
            Status: NEW
           Version: 7.0.27
         Component: Catalina
           Product: Tomcat 7

The scenario involves:

1. ServletA forwards to Servlet B
2. ServletB calls request.startAsync and starts thread
3. New thread attempts to render a JSP

I've tried JSP rendering via asyncContext.dispatch("") and via
request.getRequestDispatcher("") plus forward or include.

When using a RequestDispatcher, calling ServletA fails while calling ServletB
directly succeeds. 

When using AsyncContext.dispatch, both ServletA and ServletB fail.

The exception is always the same (while attempting to render the JSP):

java.lang.IllegalStateException: Cannot create a session after the response has
been committed

I've created a project at:
https://github.com/rstoyanchev/dispatch-test

The project page contains instructions and attached is a .war although you
might want to check the source out in order to try a couple of variations.

Beyond the specifics of the bug, the more general question is whether it is ok
to use request.getRequestDispatcher from an async thread? That seems to be the
case in Tomcat, aside from this bug, but in other containers (Jetty in
particular) it's clearly not recommended. 

Servlet Spec discussion on this question: 
http://java.net/projects/servlet-spec/lists/users/archive/2012-05/message/10.

-- 
You are receiving this mail because:
You are the assignee for the bug.

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


[Bug 53337] IllegalStateException when trying to render a JSP after startAsync

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=53337

--- Comment #3 from rstoyanchev@yahoo.com ---
Created attachment 28873
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=28873&action=edit
Updated .war file

-- 
You are receiving this mail because:
You are the assignee for the bug.

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


[Bug 53337] IllegalStateException when trying to render a JSP after startAsync

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=53337

--- Comment #5 from rstoyanchev@yahoo.com ---
I corrected one issue with the sample. Calling ServletB succeeds in all cases.
Calling ServletA doesn't. I updated the instructions at the project page and
updated the .war attachment.

-- 
You are receiving this mail because:
You are the assignee for the bug.

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


[Bug 53337] IllegalStateException when trying to render a JSP after startAsync

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=53337

--- Comment #2 from rstoyanchev@yahoo.com ---
By the way, in the description above I only meant to refer to the methods
asyncContext.dispatch and request.getRequestDispatcher. I am not actually
passing "". See the link to the source code for full details.

-- 
You are receiving this mail because:
You are the assignee for the bug.

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


[Bug 53337] IllegalStateException when trying to render a JSP after startAsync

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=53337

rstoyanchev@yahoo.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #28866|0                           |1
        is obsolete|                            |
  Attachment #28873|0                           |1
        is obsolete|                            |

--- Comment #4 from rstoyanchev@yahoo.com ---
Created attachment 28874
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=28874&action=edit
Updated .war file

-- 
You are receiving this mail because:
You are the assignee for the bug.

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


[Bug 53337] IllegalStateException when trying to render a JSP after startAsync

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=53337

--- Comment #1 from rstoyanchev@yahoo.com ---
Created attachment 28866
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=28866&action=edit
.war demonstrating the issue

-- 
You are receiving this mail because:
You are the assignee for the bug.

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


[Bug 53337] IllegalStateException when trying to render a JSP after startAsync

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=53337

Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #6 from Mark Thomas <ma...@apache.org> ---
The bug (forwarding to an async servlet always failed) has been fixed in trunk
and 7.0.x and will be included in 7.0.28 onwards.

Re-reading the spec, it appears that the intention was that dispatches from an
async thread should always be via the AsyncContext. No mention is made of
dispatching via a RequestDispatcher. This is going to be one of those grey
areas that different containers do different ways. I believe - but haven't
tested to check all the edge cases - that in Tomcat the two would be equivalent
based on which objects Tomcat uses internally. Other containers may well be
different.

My personal recommendation would be to stick with dispatching via the
AsyncContext.

-- 
You are receiving this mail because:
You are the assignee for the bug.

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


[Bug 53337] IllegalStateException when trying to render a JSP after startAsync

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=53337

--- Comment #7 from rstoyanchev@yahoo.com ---
Thanks for the suggestions, Mark.

In the discussion on the servlet-spec user list, even wider implications were
mentioned including avoiding reliance on the requestURI or even the session
from an async thread. It's quite a surprise that none of it is mentioned in the
spec.

-- 
You are receiving this mail because:
You are the assignee for the bug.

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