RFR: 6968351: httpserver clashes with delayed TCP ACKs for low Content-Length

Daniel Fuchs dfuchs at openjdk.org
Fri Apr 19 09:13:00 UTC 2024


On Sat, 6 Apr 2024 23:35:48 GMT, robert engels <duke at openjdk.org> wrote:

> fix bug JDK-B6968351 by avoiding flush after response headers

Hi Robert, thanks for working on this issue.

src/jdk.httpserver/share/classes/sun/net/httpserver/ExchangeImpl.java line 210:

> 208:         this.rcode = rCode;
> 209:         String statusLine = "HTTP/1.1 "+rCode+Code.msg(rCode)+"\r\n";
> 210:         ByteArrayOutputStream tmpout = new ByteArrayOutputStream();

Wouldn't it be better to continue using a BufferedOutputStream here? That would put a limit on how much data would be buffered when writing the headers, in case of long response headers.

test/jdk/com/sun/net/httpserver/bugs/B6968351.java line 70:

> 68:         long start = System.currentTimeMillis();
> 69:         for(int i=0;i<1000;i++) {
> 70:             var response = client.send(HttpRequest.newBuilder(new URI("http://localhost:"+server.getAddress().getPort()+"/test")).build(), HttpResponse.BodyHandlers.ofString());

It would be better to use the URI builder here and avoid "localhost:port" form to avoid dependencies on local host machines configuration.


var uri = URIBuilder.newBuilder().scheme("http").loopback().port(...).path(...).build();

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

Changes requested by dfuchs (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/18667#pullrequestreview-2010916948
PR Review Comment: https://git.openjdk.org/jdk/pull/18667#discussion_r1572066184
PR Review Comment: https://git.openjdk.org/jdk/pull/18667#discussion_r1572072507


More information about the net-dev mailing list