You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Violeta Georgieva <vi...@apache.org> on 2016/10/20 13:08:44 UTC

Question about ServletOutputStream.setWriteListener

Hi,

I have a question about ServletOutputStream.setWriteListener.

I have the following scenario:
- Request 1 - in the servlet service method it starts async operation and
starts waiting for a particular notification
- Request 2  - in the servlet service method it starts async operation and
notifies the Request 1 to write to the response
- During this notification Request 1 sets WriteListener. This happens while
we are still in the service method of the servlet for Request 2 i.e. this
happens in the thread that processes Request 2.
- Request 1 starts waiting for onWritePossible but the event is never sent.

So the question is whether it is allowed to set the WriteListener from the
thread that is processing another request?

I can see that when setWriteListener is invoked [1] we add to the
dispatches - NON_BLOCKING_WRITE - this is a result of the DISPATCH_WRITE
action.
But I think that we have to invoke DISPATCH_EXECUTE.

I tried to extract one very simple example [2] that shows the scenario.

What do you think?

Thanks,
Violeta

[1]
https://github.com/apache/tomcat/blob/trunk/java/org/apache/coyote/Response.java#L607
[2] https://github.com/violetagg/test-write-listener

Re: Question about ServletOutputStream.setWriteListener

Posted by Violeta Georgieva <mi...@gmail.com>.
2016-10-20 21:47 GMT+03:00 Mark Thomas <ma...@apache.org>:
>
> On 20/10/2016 14:08, Violeta Georgieva wrote:
> > Hi,
> >
> > I have a question about ServletOutputStream.setWriteListener.
> >
> > I have the following scenario:
> > - Request 1 - in the servlet service method it starts async operation
and
> > starts waiting for a particular notification
> > - Request 2  - in the servlet service method it starts async operation
and
> > notifies the Request 1 to write to the response
> > - During this notification Request 1 sets WriteListener. This happens
while
> > we are still in the service method of the servlet for Request 2 i.e.
this
> > happens in the thread that processes Request 2.
> > - Request 1 starts waiting for onWritePossible but the event is never
sent.
> >
> > So the question is whether it is allowed to set the WriteListener from
the
> > thread that is processing another request?
>
> Yes, but we don't handle that very well. That looks like a bug to me.
>
> > I can see that when setWriteListener is invoked [1] we add to the
> > dispatches - NON_BLOCKING_WRITE - this is a result of the DISPATCH_WRITE
> > action.
> > But I think that we have to invoke DISPATCH_EXECUTE.
> >
> > I tried to extract one very simple example [2] that shows the scenario.
>
> Can you turn that into a unit test for the AsyncContext?

http://svn.apache.org/viewvc?view=revision&revision=1765995
I added a test. It is marked with @Ignore as it will fail with the current
implementation.

Thanks,
Violeta

> Mark
>
>
> >
> > What do you think?
> >
> > Thanks,
> > Violeta
> >
> > [1]
> >
https://github.com/apache/tomcat/blob/trunk/java/org/apache/coyote/Response.java#L607
> > [2] https://github.com/violetagg/test-write-listener
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>

Re: Question about ServletOutputStream.setWriteListener

Posted by Mark Thomas <ma...@apache.org>.
On 20/10/2016 14:08, Violeta Georgieva wrote:
> Hi,
> 
> I have a question about ServletOutputStream.setWriteListener.
> 
> I have the following scenario:
> - Request 1 - in the servlet service method it starts async operation and
> starts waiting for a particular notification
> - Request 2  - in the servlet service method it starts async operation and
> notifies the Request 1 to write to the response
> - During this notification Request 1 sets WriteListener. This happens while
> we are still in the service method of the servlet for Request 2 i.e. this
> happens in the thread that processes Request 2.
> - Request 1 starts waiting for onWritePossible but the event is never sent.
> 
> So the question is whether it is allowed to set the WriteListener from the
> thread that is processing another request?

Yes, but we don't handle that very well. That looks like a bug to me.

> I can see that when setWriteListener is invoked [1] we add to the
> dispatches - NON_BLOCKING_WRITE - this is a result of the DISPATCH_WRITE
> action.
> But I think that we have to invoke DISPATCH_EXECUTE.
> 
> I tried to extract one very simple example [2] that shows the scenario.

Can you turn that into a unit test for the AsyncContext?

Mark


> 
> What do you think?
> 
> Thanks,
> Violeta
> 
> [1]
> https://github.com/apache/tomcat/blob/trunk/java/org/apache/coyote/Response.java#L607
> [2] https://github.com/violetagg/test-write-listener
> 


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