Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Question about behavior of WriteListener

Hi,

On Sun, Oct 23, 2016 at 7:31 AM, Christoph Läubrich
<laeubi@xxxxxxxxxxxxxx> wrote:
> Thanks for the clarification. I know that the write does not happen
> immediately but has expected that it at least happens for the bytes handed
> over to write.

The write does happen immediately, only there is no guarantee of how
many bytes are written.
Could be zero, could be some, could be all.

> In the "real-world" this complete can be issued by the thread writing as
> well as by a timeout listener

Not a timeout listener, if you mean AsyncListener.onTimeout().

> so it seems I have to merge both so the
> timeout knows that
> a) writing has started and
> b) then waits until writing is done

If you have an AsyncContext.timeout, then yes your application needs
to coordinate and see if the writes have completed.

> I'm just curious what happens on the wire: Will the container terminate the
> (maybe persitent) connection if it detects that content-length != bytes
> written?

If you call AsyncContext.complete() and you have a write pending,
WriteListener.onError() is called, but there is not much you can do
since the response has been committed already.
Otherwise, you don't have a write pending, and the container would
have called onWritePossible(), where you need to sync with
AsyncContext.timeout.

Can you please file an issue so that we verify that this case is
covered well in the test suite ?
The case would be these:

a) response.setContentLength(N), write N-1, then
AsyncContext.complete() -> we must error in some way and abort the
channel.
b) write pending, onTimeout() calls AsyncContext.complete(),
WriteListener.onError() is called -> verify that we abort the channel.

-- 
Simone Bordet
----
http://cometd.org
http://webtide.com
Developer advice, training, services and support
from the Jetty & CometD experts.


Back to the top