Skip to content

Commit

Permalink
http client - even safer dispatch
Browse files Browse the repository at this point in the history
make sure we call all enqueued callbacks
  • Loading branch information
hamnis committed Feb 6, 2023
1 parent 22772a2 commit fc4eacc
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit fc4eacc

Please sign in to comment.