You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Adwait Kumar Singh <ad...@gmail.com> on 2023/10/30 22:25:32 UTC
Need Help : Unable to write back a response error code from ReadListener#onError
Hi,
I am using the async Servlet API and NIO, by setting a ReadListener.
In the onError of the ReadListener, I am catching a SocketTimeoutException
and trying to send back an error code 408. Here is the simplified example
of what I am trying to do,
@Override
> public void onError(Throwable failure) {
> if(failure instanceof SocketTimeoutException) {
> response.sendError(408);
> request.getAsyncContext().complete();
> }
> }
>
>
However, Tomcat just refuses to send back the error I want and instead just
closes the connection. Am I missing something trivial or is this supposed
to be achieved in a different way?
I am using Tomcat 9.0.82 and the Http11NioEndpoint.
Thanks,
Adwait.
Re: Need Help : Unable to write back a response error code from ReadListener#onError
Posted by Adwait Kumar Singh <ad...@gmail.com>.
Sorry for the wrong bug id. This is the one I filed,
https://bz.apache.org/bugzilla/show_bug.cgi?id=68037
On Tue, Oct 31, 2023 at 3:24 PM Adwait Kumar Singh <ad...@gmail.com>
wrote:
> AFAIK the response is not being committed.
>
> I created a bug for this with a reproducible test case,
> https://bz.apache.org/bugzilla/show_bug.cgi?id=54123
>
>
> On Tue, Oct 31, 2023 at 12:49 PM Mark Thomas <ma...@apache.org> wrote:
>
>>
>>
>> On 30/10/2023 22:25, Adwait Kumar Singh wrote:
>> > Hi,
>> >
>> > I am using the async Servlet API and NIO, by setting a ReadListener.
>> >
>> > In the onError of the ReadListener, I am catching a
>> SocketTimeoutException
>> > and trying to send back an error code 408. Here is the simplified
>> example
>> > of what I am trying to do,
>> >
>> > @Override
>> >> public void onError(Throwable failure) {
>> >> if(failure instanceof SocketTimeoutException) {
>> >> response.sendError(408);
>> >> request.getAsyncContext().complete();
>> >> }
>> >> }
>> >>
>> >>
>> > However, Tomcat just refuses to send back the error I want and instead
>> just
>> > closes the connection. Am I missing something trivial or is this
>> supposed
>> > to be achieved in a different way?
>> >
>> > I am using Tomcat 9.0.82 and the Http11NioEndpoint.
>>
>> Has the response already been committed?
>>
>> If not, a minimal (ideally a single servlet) web application that
>> demonstrates the issue is often the easiest way for developers to
>> re-create the problem.
>>
>> Mark
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
Re: Need Help : Unable to write back a response error code from ReadListener#onError
Posted by Adwait Kumar Singh <ad...@gmail.com>.
AFAIK the response is not being committed.
I created a bug for this with a reproducible test case,
https://bz.apache.org/bugzilla/show_bug.cgi?id=54123
On Tue, Oct 31, 2023 at 12:49 PM Mark Thomas <ma...@apache.org> wrote:
>
>
> On 30/10/2023 22:25, Adwait Kumar Singh wrote:
> > Hi,
> >
> > I am using the async Servlet API and NIO, by setting a ReadListener.
> >
> > In the onError of the ReadListener, I am catching a
> SocketTimeoutException
> > and trying to send back an error code 408. Here is the simplified example
> > of what I am trying to do,
> >
> > @Override
> >> public void onError(Throwable failure) {
> >> if(failure instanceof SocketTimeoutException) {
> >> response.sendError(408);
> >> request.getAsyncContext().complete();
> >> }
> >> }
> >>
> >>
> > However, Tomcat just refuses to send back the error I want and instead
> just
> > closes the connection. Am I missing something trivial or is this supposed
> > to be achieved in a different way?
> >
> > I am using Tomcat 9.0.82 and the Http11NioEndpoint.
>
> Has the response already been committed?
>
> If not, a minimal (ideally a single servlet) web application that
> demonstrates the issue is often the easiest way for developers to
> re-create the problem.
>
> Mark
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
Re: Need Help : Unable to write back a response error code from ReadListener#onError
Posted by Mark Thomas <ma...@apache.org>.
On 30/10/2023 22:25, Adwait Kumar Singh wrote:
> Hi,
>
> I am using the async Servlet API and NIO, by setting a ReadListener.
>
> In the onError of the ReadListener, I am catching a SocketTimeoutException
> and trying to send back an error code 408. Here is the simplified example
> of what I am trying to do,
>
> @Override
>> public void onError(Throwable failure) {
>> if(failure instanceof SocketTimeoutException) {
>> response.sendError(408);
>> request.getAsyncContext().complete();
>> }
>> }
>>
>>
> However, Tomcat just refuses to send back the error I want and instead just
> closes the connection. Am I missing something trivial or is this supposed
> to be achieved in a different way?
>
> I am using Tomcat 9.0.82 and the Http11NioEndpoint.
Has the response already been committed?
If not, a minimal (ideally a single servlet) web application that
demonstrates the issue is often the easiest way for developers to
re-create the problem.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Need Help : Unable to write back a response error code from ReadListener#onError
Posted by Adwait Kumar Singh <ad...@gmail.com>.
FYI, I am doing the async processing on the Container thread itself, just
that I yield the thread back if I can't read without blocking.
Based on the code here
<https://github.com/apache/tomcat/blob/main/java/org/apache/coyote/AbstractProcessor.java#L121-L122>,
I see that the error is only dispatched if the request is not being
executed in the container thread.
On Mon, Oct 30, 2023 at 3:25 PM Adwait Kumar Singh <ad...@gmail.com>
wrote:
> Hi,
>
> I am using the async Servlet API and NIO, by setting a ReadListener.
>
> In the onError of the ReadListener, I am catching a SocketTimeoutException
> and trying to send back an error code 408. Here is the simplified example
> of what I am trying to do,
>
> @Override
>> public void onError(Throwable failure) {
>> if(failure instanceof SocketTimeoutException) {
>> response.sendError(408);
>> request.getAsyncContext().complete();
>> }
>> }
>>
>>
> However, Tomcat just refuses to send back the error I want and instead
> just closes the connection. Am I missing something trivial or is this
> supposed to be achieved in a different way?
>
> I am using Tomcat 9.0.82 and the Http11NioEndpoint.
>
>
> Thanks,
> Adwait.
>