From fc4eacc91bc65d8ca51fdbc02586b29324ddef42 Mon Sep 17 00:00:00 2001 From: Erlend Hamnaberg Date: Mon, 6 Feb 2023 17:09:00 +0100 Subject: [PATCH] http client - even safer dispatch make sure we call all enqueued callbacks --- .../scala/org/http4s/netty/client/Http4sHandler.scala | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/client/src/main/scala/org/http4s/netty/client/Http4sHandler.scala b/client/src/main/scala/org/http4s/netty/client/Http4sHandler.scala index 6777cf42..c1450785 100644 --- a/client/src/main/scala/org/http4s/netty/client/Http4sHandler.scala +++ b/client/src/main/scala/org/http4s/netty/client/Http4sHandler.scala @@ -79,17 +79,18 @@ private[netty] class Http4sHandler[F[_]](dispatcher: Dispatcher[F])(implicit F: key: RequestKey, callback: Either[Throwable, Resource[F, Response[F]]] => Unit): Unit = void { val ch = ctx.channel + // always enqueue + promises.enqueue(callback) if (ch.isActive) { - promises.enqueue(callback) logger.trace(s"ch $ch: sending request to $key") // The voidPromise lets us receive failed-write signals from the // exceptionCaught method. ctx.writeAndFlush(request, ch.voidPromise) logger.trace(s"ch $ch: after request to $key") } else { - logger.info( - s"ch $ch: message dispatched by closed channel to destination ${ch.remoteAddress}.") - callback(Left(new ClosedChannelException)) + // make sure we call all enqueued promises + logger.info(s"ch $ch: message dispatched by closed channel to destination $key.") + onException(ctx, new ClosedChannelException) } }