You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Istvan SZEKELY <is...@shiwaforce.com> on 2022/02/24 09:31:09 UTC

Tomcat 8.5.75 Servlet WriteListener and ReadListener setting thread

Hello!

I have an application where a ReadListener and a WriteListener (call it
MyWriteListener) set to the ServletInputStream and the ServletOutputStream
objects. Updating the Tomcat container from 8.5.73 to 8.5.75, the follow
error occured. The ServletOutputStream objects's isReady function always
returns false (within MyWriteListener.onWritePossible).

I think its because of this commit:
https://github.com/apache/tomcat/commit/2bfbbef65d1b1b07da46c8dcd6cee96cb5567998#diff-1ffbc1c154370a6c5385c168a0846a1c385aacbf5f880feb74cb1c27baa76003

The ReadListener is set first, where dispatch fired
(action(ActionCode.DISPATCH_EXECUTE, null);). There the request threadId
updated (req.setRequestThread();).
Then  when i'm setting the WriteListener (within the same thread), the
DISPACTH_EXECUTE action not fired (due to threadId equals request objects
thread id).  Thus registeredForWrite flag remains is true state, causing
the isReady false behaviour.

Is this a Tomcat bug, or I should do something differently. I could't set
WriteListener within a different thread, but it feels weird. Should i do
something else?

Thank You in Advance,
 Istvan

Re: Tomcat 8.5.75 Servlet WriteListener and ReadListener setting thread

Posted by Rémy Maucherat <re...@apache.org>.
On Thu, Feb 24, 2022 at 10:31 AM Istvan SZEKELY
<is...@shiwaforce.com> wrote:
>
> Hello!
>
> I have an application where a ReadListener and a WriteListener (call it
> MyWriteListener) set to the ServletInputStream and the ServletOutputStream
> objects. Updating the Tomcat container from 8.5.73 to 8.5.75, the follow
> error occured. The ServletOutputStream objects's isReady function always
> returns false (within MyWriteListener.onWritePossible).
>
> I think its because of this commit:
> https://github.com/apache/tomcat/commit/2bfbbef65d1b1b07da46c8dcd6cee96cb5567998#diff-1ffbc1c154370a6c5385c168a0846a1c385aacbf5f880feb74cb1c27baa76003
>
> The ReadListener is set first, where dispatch fired
> (action(ActionCode.DISPATCH_EXECUTE, null);). There the request threadId
> updated (req.setRequestThread();).
> Then  when i'm setting the WriteListener (within the same thread), the
> DISPACTH_EXECUTE action not fired (due to threadId equals request objects
> thread id).  Thus registeredForWrite flag remains is true state, causing
> the isReady false behaviour.
>
> Is this a Tomcat bug, or I should do something differently. I could't set
> WriteListener within a different thread, but it feels weird. Should i do
> something else?

I think I see the problem, but would you have test code or example
like this testcase to submit ?
https://github.com/apache/tomcat/blob/main/test/org/apache/catalina/nonblocking/TestNonBlockingAPI.java#L951
It would allow verifying and validating a fix.

Rémy

> Thank You in Advance,
>  Istvan

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