RFR: 7026262: HttpServer: improve handling of finished HTTP exchanges

Daniel Jeliński djelinski at openjdk.org
Fri Mar 24 07:42:30 UTC 2023


On Thu, 23 Mar 2023 18:34:37 GMT, Daniel Fuchs <dfuchs at openjdk.org> wrote:

>> This patch fixes the following issues with HttpHandler exception handling:
>> - The connection is no longer closed if an exception is thrown after the response is completed. As soon as the response is completed, the connection is added back to the pool, ready for reuse. Closing the connection would race with the subsequent handler.
>> - The stream returned by `getResponseBody` is now usable even if the response has zero-length body. Writing any data to the stream will still fail, but zero-length writes and closing the stream will now succeed.
>> - `ServerImpl.Exchange.reject` now sends a `Connection: close` header in addition to closing the connection
>> 
>> The test `B8293562` had to be adjusted to avoid `Connection: close`.
>> Additionally, while I was looking for a good test to copy from, I found and fixed a bug in test `B5045306`.
>> 
>> The new tests are passing with this patch, failing without it. Tier 1-3 clean.
>
> src/jdk.httpserver/share/classes/sun/net/httpserver/FixedLengthOutputStream.java line 89:
> 
>> 87:             // WriteFinishedEvent was sent already; nothing to do
>> 88:             return;
>> 89:         }
> 
> Wouldn't it be more correct to have sendResponseHeader close the output stream, and let the output stream `close` generate the write event, rather than having sendResponseHeader generate the event and not doing anything here? Or would there be an issue with the case where the stream is chunked output stream?

`sendResponseStream` could close the stream when called with length = -1; the output stream is always fixed length in that case. I'd need to modify this class to accept zero-length writes even when closed, but I think there's a precedent for that already. Will look into it.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/13157#discussion_r1147213625


More information about the net-dev mailing list