Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] EXTERNAL: Re: jetty client delivers incomplete response without exception?

Hi,

On Wed, Apr 20, 2022 at 8:27 AM Robben, Bert <Bert.Robben@xxxxxxxxxxxxx> wrote:
>
> > The client knows how many bytes from the `Content-Length` header; if it sees less, it produces an EOF exception.
> > If the content is chunked, it expects the terminating chunk; if it does not see it, it produces an EOF exception.
>
> Our server-side resource does not set the Content-Length header. It doesn't do this because it has no idea up-front what the size will be. It traverses a huge data structure and writes that in json-form to the response stream. The data structure is never in-memory in its entirety because the total size can go > 1 Gb. As such, the resource also writes the json piece-by-piece.
>
> In pseudo-code, that would go more or less like this
>
> response.write('[');
> for (int part = 0; part < someBigNumber; part++) {
>    if (part != 0) response.write(',');
>    objectMapper.writeAsJson(producePart(part), response);
> }
> response.write(']');
> response.close();
>
> The real code is more complicated than shown here because it does all of this asynchronously, but it should still give a good idea of what is going on.

If the content is small (less than 32 KiB IIRC), then Jetty buffers
the writes and when it sees the close can figure out the
Content-Length.
If the content is large (your case), Jetty will chunk (i.e.
Transfer-Encoding: chunked).

> I can imagine that if the connection is cut somewhere in the middle of some tcp package that we'll see this as an IOEXception.

Correct.

> If the connection is cut at a moment that no data is being transferred (because the server-side resource is e.g. still producing some part) then I can understand that the client is not aware of a problem and doesn't throw.

No, the client will know.
The client will see a TCP FIN/RST without having received the
terminator chunk, so it will know that not all content has arrived.

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


Back to the top