Skip to content

REST client doesn't receive the response from PATCH API call #34724

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sharmasourabh opened this issue Apr 6, 2025 · 7 comments
Closed

REST client doesn't receive the response from PATCH API call #34724

sharmasourabh opened this issue Apr 6, 2025 · 7 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: invalid An issue that we don't feel is valid

Comments

@sharmasourabh
Copy link

Spring Boot Version: 3.4.4

Do we need to configure something extra for using the HTTP method PATCH?
When client sends the PATCH REST call to spring boot server, controller method receives the request and sends the request back by wrapping the response in ok() method. However, client doesn't receive the response back and keep waiting for response.

The moment method mapping is replaced from PATCH to PUT. REST call works and client receives the response.

Log for PATCH call:

20:58:13.790 [http-nio-8080-exec-4] DEBUG o.s.orm.jpa.JpaTransactionManager - Initiating transaction commit
20:58:13.790 [http-nio-8080-exec-4] DEBUG o.s.orm.jpa.JpaTransactionManager - Committing JPA transaction on EntityManager [SessionImpl(1438170547<open>)]
20:58:13.790 [http-nio-8080-exec-4] DEBUG o.h.e.t.internal.TransactionImpl - committing
20:58:13.790 [http-nio-8080-exec-4] DEBUG o.s.orm.jpa.JpaTransactionManager - Not closing pre-bound JPA EntityManager after transaction
20:58:13.791 [http-nio-8080-exec-4] DEBUG o.s.w.s.m.m.a.HttpEntityMethodProcessor - Using 'application/json', given [application/json] and supported [application/json, */*]
20:58:13.791 [http-nio-8080-exec-4] DEBUG o.s.w.s.m.m.a.HttpEntityMethodProcessor - Writing [class XYZ {<EOL>    id: 1<EOL>    name: null<EOL>    field1: null<EOL>    feild2: {}<EOL>}]
20:58:13.792 [http-nio-8080-exec-4] DEBUG o.s.o.j.s.OpenEntityManagerInViewInterceptor - Closing JPA EntityManager in OpenEntityManagerInViewInterceptor
20:58:13.792 [http-nio-8080-exec-4] DEBUG o.s.web.servlet.DispatcherServlet - Completed 200 OK

Then, nothing happens and client keep waiting for response.
When request is cancelled by the client:

20:58:18.774 [http-nio-8080-exec-5] DEBUG o.a.coyote.http11.Http11Processor - Error parsing HTTP request header
java.io.EOFException: null
	at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.fillReadBuffer(NioEndpoint.java:1295)
	at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.read(NioEndpoint.java:1183)
	at org.apache.coyote.http11.Http11InputBuffer.fill(Http11InputBuffer.java:795)
	at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:351)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:270)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:905)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1743)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
	at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1190)
	at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63)
	at java.base/java.lang.Thread.run(Thread.java:1583)
20:58:18.774 [http-nio-8080-exec-5] DEBUG o.a.coyote.http11.Http11Processor - Error state [CLOSE_CONNECTION_NOW] reported while processing request
java.io.EOFException: null
	at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.fillReadBuffer(NioEndpoint.java:1295)
	at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.read(NioEndpoint.java:1183)
	at org.apache.coyote.http11.Http11InputBuffer.fill(Http11InputBuffer.java:795)
	at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:351)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:270)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:905)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1743)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
	at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1190)
	at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63)
	at java.base/java.lang.Thread.run(Thread.java:1583)
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 6, 2025
@bclozel
Copy link
Member

bclozel commented Apr 6, 2025

Please provide a minimal sample application.

@bclozel bclozel added the status: waiting-for-feedback We need additional information before we can continue label Apr 6, 2025
@bclozel bclozel transferred this issue from spring-projects/spring-boot Apr 6, 2025
@sharmasourabh
Copy link
Author

sharmasourabh commented Apr 7, 2025

Please find the sample application here

$ curl --request GET \
  --url http://localhost:8080/v1/testobj/1 \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json'

{"id":1,"name":"name","ranks":null,"stocks":{}}

$ curl --request PATCH \
  --url http://localhost:8080/v1/testobj/1 \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data '{
	"stocks": [
		 "532483","526829"
	],
	"action": "remove"
}'

PATCH request logs: (Unlike GET call, response is returned but not received by the client)

2025-04-07T12:01:53.460+05:30  INFO 49683 --- [demo] [nio-8080-exec-3] c.e.demo.controller.TestObjController    : Patch request received for id - 1
2025-04-07T12:01:53.461+05:30  INFO 49683 --- [demo] [nio-8080-exec-3] c.e.demo.controller.TestObjController    : Patch request's response being sent...

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Apr 7, 2025
@jhoeller jhoeller added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Apr 7, 2025
@bclozel bclozel self-assigned this Apr 8, 2025
@SheikhSuhail19
Copy link

Hello @bclozel ,

If nobody is actively working on this, I can pick it up. Please let me know.
Thanks

@bclozel
Copy link
Member

bclozel commented Apr 10, 2025

I can't reproduce the issue you're seeing. Please advise.

➜  PatchDemo git:(main) curl --version
curl 8.7.1 (x86_64-apple-darwin24.0) libcurl/8.7.1 (SecureTransport) LibreSSL/3.3.6 zlib/1.2.12 nghttp2/1.64.0
Release-Date: 2024-03-27
Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns ldap ldaps mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS GSS-API HSTS HTTP2 HTTPS-proxy IPv6 Kerberos Largefile libz MultiSSL NTLM SPNEGO SSL threadsafe UnixSockets

➜  PatchDemo git:(main) curl --request PATCH \
  --url http://localhost:8080/v1/testobj/1 \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data '{
        "stocks": [
                 "532483","526829"
        ],
        "action": "remove"
}' -v
* Host localhost:8080 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying [::1]:8080...
* Connected to localhost (::1) port 8080
> PATCH /v1/testobj/1 HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/8.7.1
> Accept: application/json
> Content-Type: application/json
> Content-Length: 61
>
* upload completely sent off: 61 bytes
< HTTP/1.1 200
< Content-Type: application/json
< Transfer-Encoding: chunked
< Date: Thu, 10 Apr 2025 07:01:04 GMT
<
* Connection #0 to host localhost left intact
{"id":1,"name":"name","ranks":null,"stocks":{}}%

@bclozel bclozel added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Apr 10, 2025
@sharmasourabh
Copy link
Author

Thanks @bclozel for looking into it.

I am also using the same cURL version on Mac. Even I tried using Insomnia API client too. No luck. Interesting thing is all other HTTP methods work fine. Please look at the attached gif.

Image

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Apr 11, 2025
@bclozel
Copy link
Member

bclozel commented Apr 11, 2025

My best guess is that this is due to your local setup. Maybe a local firewall or antivirus?

In the meantime I will close this issue as it appears unrelated to Spring.

@bclozel bclozel closed this as not planned Won't fix, can't repro, duplicate, stale Apr 11, 2025
@bclozel bclozel added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged or decided on status: feedback-provided Feedback has been provided labels Apr 11, 2025
@taarh
Copy link

taarh commented Apr 11, 2025

Hello,

Could you please share an example using the PUT method?
As you mentioned earlier, it works with PUT, but in the demo you provided, the example uses GET.
Could you please provide an example with PUT instead?

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

6 participants