JDK-8211858 : java.net.http.HttpClient fails to timely recognize 204 response
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: repo-portola
  • Priority: P4
  • Status: Resolved
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86_64
  • Submitted: 2018-09-25
  • Updated: 2022-11-30
  • Resolved: 2022-11-30
Related Reports
Relates :  
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
Linux-x64, Alpine Linux, musl, openjdk-11 build 28

A DESCRIPTION OF THE PROBLEM :
java.net.http.HttpClient does not provide response (status 204) until 1 minute has passed. This appears to correlate with some sort of keep-alive or timeout configuration and not with response time from http server.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
The following steps requires that docker is installed:
1. $ git clone https://github.com/kimcs/javanethttp204bug.git
2. $ cd javanethttp204bug
3. $ docker build -t javanethttp204bug .
4. $ docker run -it javanethttp204bug

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expected all http requests to respond within at most a few milliseconds, including the response with status-code 204.
ACTUAL -
A 1 minute wait-time to recognize the 204 response. Standard out produce a "TEST FAILED" line at the very end.

---------- BEGIN SOURCE ----------
https://github.com/kimcs/javanethttp204bug
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Either of the following are workarounds:
1. Not using musl linked JDK 11 for Alpine Linux distributions, rather use JDK 11 linked to normal glibc.
2. Not using 204 response code in your http-server application. E.g. use 200 instead.


Comments
Most likely a duplicate of JDK-8211437, which was fixed in 11.0.2. The original MUSL binary is no longer available on download.java.net.
30-11-2022

The bug had been submitted for repo-portola but this is reproducible on ubuntu 14.0.4 also. Oracle JDK 11 - Fail Output: REQUEST 1 Client sending GET request expecting status: 200 Undertow sending response with statuscode: 200 Client received response with Status: 200, Body: "Hello from Undertow, echoing statuscode 200" Retrying request using URL client. Undertow sending response with statuscode: 200 HTTP/1.1 200 OK Connection: keep-alive Content-Length: 43 Date: Mon, 08 Oct 2018 14:08:56 GMT Hello from Undertow, echoing statuscode 200 REQUEST 2 Client sending GET request expecting status: 204 Undertow sending response with statuscode: 204 Client received response with Status: 204, Body: "" Retrying request using URL client. Undertow sending response with statuscode: 204 HTTP/1.1 204 No Content Date: Mon, 08 Oct 2018 14:09:57 GMT TEST FAILED. Http request spent 60 seconds to complete (URL retry spent 0 seconds), GET with status 204
08-10-2018