-
Notifications
You must be signed in to change notification settings - Fork 413
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ZClient] Unsafely fulfil promises to avoid race conditions (#2843)
Unsafely fulfill Client promises to avoid race conditions
- Loading branch information
1 parent
1822f19
commit 21d5324
Showing
6 changed files
with
55 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 5 additions & 8 deletions
13
zio-http/jvm/src/main/scala/zio/http/netty/client/ClientFailureHandler.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,22 @@ | ||
package zio.http.netty.client | ||
|
||
import zio.{Promise, Trace, Unsafe} | ||
import zio.{Exit, Promise, Unsafe} | ||
|
||
import zio.http.Response | ||
import zio.http.internal.ChannelState | ||
import zio.http.netty.NettyRuntime | ||
|
||
import io.netty.channel.{ChannelHandlerContext, ChannelInboundHandlerAdapter} | ||
|
||
/** Handles failures happening in ClientInboundHandler */ | ||
final class ClientFailureHandler( | ||
rtm: NettyRuntime, | ||
onResponse: Promise[Throwable, Response], | ||
onComplete: Promise[Throwable, ChannelState], | ||
)(implicit trace: Trace) | ||
extends ChannelInboundHandlerAdapter { | ||
) extends ChannelInboundHandlerAdapter { | ||
implicit private val unsafeClass: Unsafe = Unsafe.unsafe | ||
|
||
override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = { | ||
rtm.runUninterruptible(ctx, NettyRuntime.noopEnsuring)( | ||
onResponse.fail(cause) *> onComplete.fail(cause), | ||
)(unsafeClass, trace) | ||
val exit = Exit.fail(cause) | ||
onResponse.unsafe.done(exit) | ||
onComplete.unsafe.done(exit) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters