okhttp: OkHttp does not close connection when server sends a FIN, ACK
We’ve recently encountered an issue on production wherein an HTTP server, which is shutting down, sends back a FIN, ACK
packet, but OkHttp still continues sending traffic on that connection instead of closing it and started a new connection.
Here is a screenshot of one such incident on Wireshark on my local setup (10.101.84.85
is the server, 172.17.0.6
is the client),
My test setup is as follows,
- Hosted on Kubernetes.
- Client side running using OkHttp 4.5.0 (Java 18)
- Server side running a Golang HTTP server (Golang 1.18)
- Client side uses Kubernetes FQDN to talk to the server.
- Client maintains a connection pool of 10 connections.
- Client side code: https://gist.github.com/tejasjadhav/d5a4b4efca8e7400236ce18e86dcb00a#file-app-java
- Server side code: https://gist.github.com/tejasjadhav/d5a4b4efca8e7400236ce18e86dcb00a#file-main-go
Expectation
OkHttp client should remove the connection from the pool when server sends back FIN, ACK
packet.
Actual
OkHttp does not terminate the connection for which server sends back FIN, ACK
packet and still sends traffic on that connection, which results in a connection resets and failures on subsequent calls.
Steps to reproduce
- Create an OkHttp client with a connection pool to an HTTP server.
- Make 1-2 requests using that client to initialise the pool.
- Shutdown the server. Observe that
FIN, ACK
packets are being sent by the server on shutdown. - While the server is shutting down, send 1-2 requests using the OkHttp client.
- The requests should fail with an error
unexpected end of stream
. Server would have sent anRST
in response.
Environment
- OkHttp 4.5.0
- Java 18
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 15
@yschimke tried it on OkHttp 4.9.3. Still seeing the same behavior
Thank you for your quick reply! Apologies, the issue is actually occurring when using version 4.11.0.
https://github.com/apache/nifi/blob/rel/nifi-1.23.2/pom.xml#L111
I was referencing an outdated pom.