You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Peter Cipov <pc...@kerio.com> on 2013/05/27 15:43:46 UTC
NPE in coyote InternalNioOutputBuffer
Hello
I have the commet application - some sort of event bus where requests are
turned in async mode then stored in internal cache and when event occures
/ or request times out response is sent back to subscriber (it is handled
with my executor worker threads).
It worked fine until I have added a line with calling flushBuffer on
response object. My goal was to mark the connection as commited - I am
checking whether I have already written to this response
(response.isCommited()) in some other part of my code.
Now errors like these pop out in my logs
java.lang.NullPointerException
at
org.apache.coyote.http11.InternalNioOutputBuffer.addToBB(InternalNioOutputBuffer.java:210)
at
org.apache.coyote.http11.InternalNioOutputBuffer.commit(InternalNioOutputBuffer.java:202)
at
org.apache.coyote.http11.AbstractHttp11Processor.action(AbstractHttp11Processor.java:765)
at org.apache.coyote.Response.action(Response.java:174)
at org.apache.coyote.Response.sendHeaders(Response.java:354)
at
org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:330)
at org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:306)
at org.apache.catalina.connector.Response.flushBuffer(Response.java:568)
at
org.apache.catalina.connector.ResponseFacade.flushBuffer(ResponseFacade.java:307)
.... my code calling flushBuffer() on HttpResponse object
....
.... worker thread
public void send(HttpServletResponse response) { // calling from worker
threads
if (response.isCommitted()) {
throw new IOException("ERROR");
}
response.getWriter().print("RESPONSE");
response.flushBuffer(); // <---- FAILED HERE
}
Did I miss some curtial lesson about flushing async responses ?
PS.
By the way that NPE should never occur - Is it a BUG ? I am using Tomcat
7.0.28 (current in debian 7.0 Wheezy)
--
Peter Cipov
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: NPE in coyote InternalNioOutputBuffer
Posted by Peter Cipov <pc...@kerio.com>.
> a) are not thread-safe
> b) are cached and reused for subsequent incoming requests.
Thanks for helpful response.
I did not expect these tomcat "features"...
Now I am reinspecting my implementation and I have found one place that
seems fuzzy to me.
public void onTimeout(AsyncEvent ae) throws IOException {
ae.getAsyncContext().getResponse().getWriter().write("no changes");
}
There is not much in the documentation.
AsyncListener has method onTimeout. I am using it to inform subscribers
that there is no change. Is it legal to sent back some response on timeout
(like "no changes") ? No recycle can happen during this action ? I have
looked in the sources and request recycle is called after this listener is
executed.
I just want to be sure that this order is always the same and any other
tomcat feature will not interfere.
best regards
Peter Cipov
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: NPE in coyote InternalNioOutputBuffer
Posted by Konstantin Kolinko <kn...@gmail.com>.
2013/5/27 Peter Cipov <pc...@kerio.com>:
> Hello
>
> I have the commet application - some sort of event bus where requests are
> turned in async mode then stored in internal cache and when event occures /
> or request times out response is sent back to subscriber (it is handled with
> my executor worker threads).
>
> It worked fine until I have added a line with calling flushBuffer on
> response object. My goal was to mark the connection as commited - I am
> checking whether I have already written to this response
> (response.isCommited()) in some other part of my code.
> Now errors like these pop out in my logs
>
> java.lang.NullPointerException
> at
> org.apache.coyote.http11.InternalNioOutputBuffer.addToBB(InternalNioOutputBuffer.java:210)
> at
> org.apache.coyote.http11.InternalNioOutputBuffer.commit(InternalNioOutputBuffer.java:202)
> at
> org.apache.coyote.http11.AbstractHttp11Processor.action(AbstractHttp11Processor.java:765)
> at org.apache.coyote.Response.action(Response.java:174)
> at org.apache.coyote.Response.sendHeaders(Response.java:354)
> at
> org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:330)
> at
> org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:306)
> at
> org.apache.catalina.connector.Response.flushBuffer(Response.java:568)
> at
> org.apache.catalina.connector.ResponseFacade.flushBuffer(ResponseFacade.java:307)
> .... my code calling flushBuffer() on HttpResponse object
> ....
> .... worker thread
>
>
> public void send(HttpServletResponse response) { // calling from worker
> threads
> if (response.isCommitted()) {
> throw new IOException("ERROR");
> }
> response.getWriter().print("RESPONSE");
> response.flushBuffer(); // <---- FAILED HERE
> }
>
>
> Did I miss some curtial lesson about flushing async responses ?
HttpServletRequest and HttpServletResponse objects
a) are not thread-safe
b) are cached and reused for subsequent incoming requests.
so what are you doing to ensure that you do not access it concurrently
and beyond its life cycle?
I would recommend to configure the following system property in the
catalina.properties file:
org.apache.catalina.connector.RECYCLE_FACADES=true
It will prevent reuse of those objects.
http://tomcat.apache.org/tomcat-7.0-doc/config/systemprops.html
> PS.
> By the way that NPE should never occur - Is it a BUG ? I am using Tomcat
> 7.0.28 (current in debian 7.0 Wheezy)
It is old, as Chuck noted.
Best regards,
Konstantin Kolinko
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: NPE in coyote InternalNioOutputBuffer
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Peter Cipov [mailto:pcipov@kerio.com]
> Subject: NPE in coyote InternalNioOutputBuffer
> Did I miss some curtial lesson about flushing async responses ?
> By the way that NPE should never occur - Is it a BUG ? I am using Tomcat
> 7.0.28 (current in debian 7.0 Wheezy)
That level is almost one year old, and numerous fixes have gone in since then related to handling async requests and responses (check the changelog for details). You need to install the current Tomcat (7.0.40) and see if the issue has been addressed.
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org