users@servlet-spec.java.net

[servlet-spec users] [jsr369-experts] Re: Clarification of threading requirements of section 6.2.3

From: Greg Wilkins <gregw_at_intalio.com>
Date: Sat, 6 Dec 2014 23:40:15 +0100

Mark,

the problem with allowing a filter chain and servlet to be invoked from
another thread like that (even if run through AsyncContext.start(Runnable))
is that any exceptions thrown will not be correctly handled an error page
dispatch.

There is also the scope of the FilterChain to be considered. Can it be
reused like RequestDispatchers between different threads?

I think there are probably other complications that we have not yet thought
about, so I'm leaning towards this being illegal.

Note that same issue has currently been raised against Jetty, and while
I've not had time to fully understand the use-case yet, it does look like a
valid use case... but perhaps it needs a different way of integrating with
a container rather than interrupting the filterchain.

cheers






On 6 December 2014 at 01:14, Mark Thomas <markt_at_apache.org> wrote:

> Hi,
>
> Section 6.2.3 includes the following text:
> <quote>
> A Filter and the target servlet or resource at the end of the filter
> chain must execute in the same invocation thread.
> </quote>
>
> As a result of a bug raised against Apache Tomcat [1] I am seeking
> clarification of the meaning of that sentence.
>
> As written, the meaning seems unambiguous. However, does it apply when
> the request is in asynchronous mode? To put it another way is the
> following legal?
> - filter calls ServletRequest.startAsync()
> - filter calls AsyncContext.start(Runnable)
> - That Runnable called FilterChain.doFilter()
>
> If the above were legal it creates some implementation issues for the
> containers but they are not insurmountable. Clearly there is a user
> requirement to do this else the bug would not have been raised.
>
> Looking back at the original discussion that led to this text being
> added, async behaviour was not considered.
>
> So is the above legal, in which case we need to clarify 6.2.3 or is it
> illegal? I'm currently leaning towards it being legal.
>
> Mark
>
>
> [1] https://issues.apache.org/bugzilla/show_bug.cgi?id=57284
>



-- 
Greg Wilkins <gregw_at_intalio.com>  @  Webtide - *an Intalio subsidiary*
http://eclipse.org/jetty HTTP, SPDY, Websocket server and client that scales
http://www.webtide.com  advice and support for jetty and cometd.