Hi
I am currently running an application using sttp and a HttpClientZioBackend, the server is behind a nginx that uses http2 and I noticed in the log that every hour, I get a stack trace with a
ent3.SttpClientException$ReadException: Exception when sending request: GET https://httpserver.com
at sttp.client3.SttpClientExceptionExtensions.defaultExceptionToSttpClientException(SttpClientExceptionExtensions.scala:25)
at sttp.client3.SttpClientExceptionExtensions.defaultExceptionToSttpClientException$(SttpClientExceptionExtensions.scala:9)
at sttp.client3.SttpClientException$.defaultExceptionToSttpClientException(SttpClientException.scala:24)
at sttp.client3.HttpClientAsyncBackend.adjustExceptions$$anonfun$1(HttpClientAsyncBackend.scala:147)
at sttp.client3.SttpClientException$$anon$1.applyOrElse(SttpClientException.scala:35)
at sttp.client3.SttpClientException$$anon$1.applyOrElse(SttpClientException.scala:34)
at zio.ZIO.tryRescue$1$$anonfun$1(ZIO.scala:359)
at scala.util.Either.fold(Either.scala:190)
at zio.ZIO.tryRescue$1(ZIO.scala:359)
at zio.ZIO.catchSome$$anonfun$1(ZIO.scala:361)
Suppressed: java.io.IOException: /xxxxxxx:36150: GOAWAY received
It seems that this is related to the Module ngx_http_core_module (or keepalive_time) from nginx, which reset the connection every hour. This issue seems to be documented java - How to handle HTTP/2 GOAWAY with HttpClient? - Stack Overflow as well and I was wondering if there was a clean way to deal with that and maybe retry in case of GOAWAY using sttp ?
I could also provide a custom http client that explicitly disable HTTP2 to the HttpClientZioBackend, but that feels like a step backward.
Sorry if this is out of the scope of sttp
as of now, the only workaround that I can think of is doing that
request = backend
.send(request.response(asBoth(request.response, asStringAlways)))
result <- request.catchSome {
case exception: SttpClientException.ReadException if exception.getCause.toString.contains("GOAWAY") =>
request
}
which should work, another solution could be to switch to Armeria which seems to support http2 correctly (https://github.com/line/armeria/blob/def2dd761213d341b0d17c9ce52c636cf8edfa5e/core/src/main/java/com/linecorp/armeria/internal/common/Http2GoAwayHandler.java#L75)