http4s / http4s

A minimal, idiomatic Scala interface for HTTP
https://http4s.org/
Apache License 2.0
2.52k stars 789 forks source link

Ember Client : Retry when connection reset on JDK 17+ #7472

Closed Dichotomia closed 3 days ago

Dichotomia commented 1 week ago

On JDK 17+, the exception has changed when a connection reset occured.

We have this stack trace :

java.io.IOException: Connection reset at java.base/sun.nio.ch.UnixAsynchronousSocketChannelImpl.finishRead(Unknown Source) at java.base/sun.nio.ch.UnixAsynchronousSocketChannelImpl.finish(Unknown Source) at java.base/sun.nio.ch.UnixAsynchronousSocketChannelImpl.onEvent(Unknown Source) at java.base/sun.nio.ch.EPollPort$EventHandlerTask.run(Unknown Source) at java.base/sun.nio.ch.AsynchronousChannelGroupImpl$1.run(Unknown Source) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.base/java.lang.Thread.run(Unknown Source) at delay @ fs2.io.net.SocketCompanionPlatform$AsyncSocket.readChunk$$anonfun$1(SocketPlatform.scala:120) at async @ fs2.io.net.SocketCompanionPlatform$AsyncSocket.readChunk(SocketPlatform.scala:120) at flatMap @ fs2.io.net.SocketCompanionPlatform$BufferedReads.read$$anonfun$1(SocketPlatform.scala:84) at delay @ fs2.io.net.SocketCompanionPlatform$BufferedReads.withReadBuffer(SocketPlatform.scala:58) at flatten$extension @ org.http4s.ember.server.internal.Shutdown$$anon$1.(Shutdown.scala:71) at getAndSet @ org.typelevel.keypool.KeyPool$.destroy(KeyPool.scala:120) at apply @ org.http4s.ember.server.EmberServerBuilder.build$$anonfun$2(EmberServerBuilder.scala:235)

This patch used in production enables us to avoid this kind of error.

Dichotomia commented 1 week ago

I think it is linked to this commit on the JDK https://github.com/openjdk/jdk/commit/3a4d5db248d74020b7448b64c9f0fc072fc80470

And the exception is created here https://github.com/openjdk/jdk/blob/50bed6c67b1edd7736bdf79308d135a4e1047ff0/src/java.base/unix/classes/sun/nio/ch/UnixAsynchronousSocketChannelImpl.java#L425