Version:

 'org.springframework.boot' version '2.6.3'
 'io.spring.dependency-management' version '1.0.11.RELEASE'

Use the Spring Initializer to generate a project with a single dependency

  implementation 'org.springframework.boot:spring-boot-starter-web'

The send a GET request to a non-existing URL, the 404 response is closed normally as expected.

➜ curl -sv   -X GET http://localhost:8080/mytest
*   Trying ::1:8080...
* Connected to localhost (::1) port 8080 (#0)
> GET /mytest HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.77.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 404
< Vary: Origin
< Vary: Access-Control-Request-Method
< Vary: Access-Control-Request-Headers
< Content-Type: application/json
< Transfer-Encoding: chunked
< Date: Wed, 26 Jan 2022 12:29:52 GMT
<
* Connection #0 to host localhost left intact
{"timestamp":"2022-01-26T12:29:52.483+00:00","status":404,"error":"Not Found","path":"/mytest"}%

Then try to send a HEAD request to the same non-existing URL, the response hangs.

curl -sv   -X HEAD http://localhost:8080/mytest
*   Trying ::1:8080...
* Connected to localhost (::1) port 8080 (#0)
> HEAD /mytest HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.77.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 404
< Vary: Origin
< Vary: Access-Control-Request-Method
< Vary: Access-Control-Request-Headers
< Content-Type: application/json
< Transfer-Encoding: chunked
< Date: Wed, 26 Jan 2022 12:29:58 GMT

Comment From: bclozel

I think curl is wrongly used here. The -X argument only changes the HTTP method sent, but does not change the behavior from the client - in this case, expecting a response body. Using --head behaves as expected. Note that with the curl version on my machine, I'm getting a warning against this usage pattern precisely.

➜  ~ curl --version
curl 7.77.0 (x86_64-apple-darwin21.0) libcurl/7.77.0 (SecureTransport) LibreSSL/2.8.3 zlib/1.2.11 nghttp2/1.42.0

➜  ~ curl -X HEAD http://localhost:8080/mytest
Warning: Setting custom HTTP method to HEAD with -X/--request may not work the
Warning: way you want. Consider using -I/--head instead.
^C

➜  ~ curl --head http://localhost:8080/mytest
HTTP/1.1 404
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Content-Type: application/json
Transfer-Encoding: chunked
Date: Wed, 26 Jan 2022 13:07:53 GMT

Unless I've missed something, I'm closing this issue as invalid.