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), Screenshot 2022-01-31 at 6 27 11 PM

My test setup is as follows,

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

  1. Create an OkHttp client with a connection pool to an HTTP server.
  2. Make 1-2 requests using that client to initialise the pool.
  3. Shutdown the server. Observe that FIN, ACK packets are being sent by the server on shutdown.
  4. While the server is shutting down, send 1-2 requests using the OkHttp client.
  5. The requests should fail with an error unexpected end of stream. Server would have sent an RST in response.

Environment

  • OkHttp 4.5.0
  • Java 18

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 15

Most upvoted comments

@yschimke tried it on OkHttp 4.9.3. Still seeing the same behavior

Screenshot 2022-01-31 at 9 44 44 PM 1

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.