Skip to content

Commit

Permalink
Fix: Propagate FiberRef To HttpRuntime (#1379)
Browse files Browse the repository at this point in the history
* propagate fiberrefs to http runtime

* don't propagate fiber scope
  • Loading branch information
adamgfraser committed Jul 31, 2022
1 parent c48b414 commit c11a5c1
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions zio-http/src/main/scala/zhttp/service/HttpRuntime.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package zhttp.service

import io.netty.channel.{ChannelHandlerContext, EventLoopGroup => JEventLoopGroup}
import io.netty.util.concurrent.{EventExecutor, Future, GenericFutureListener}
import io.netty.util.concurrent.{Future, GenericFutureListener}
import zio._

import scala.collection.mutable
import scala.jdk.CollectionConverters._

/**
Expand Down Expand Up @@ -85,20 +84,18 @@ object HttpRuntime {
* the server.
*/
def sticky[R](group: JEventLoopGroup): URIO[R, HttpRuntime[R]] =
for {
rtm <- ZIO.runtime[R]
env <- ZIO.environment[R]
} yield {
val map = mutable.Map.empty[EventExecutor, Runtime[R]]
group.asScala.foreach { e =>
val executor = Executor.fromJavaExecutor(e)
val rtm = Unsafe.unsafeCompat { implicit u =>
Runtime.unsafe.fromLayer(Runtime.setExecutor(executor)).withEnvironment(env)
ZIO.runtime[R].flatMap { runtime =>
ZIO
.foreach(group.asScala) { javaExecutor =>
val executor = Executor.fromJavaExecutor(javaExecutor)
ZIO.runtime[R].daemonChildren.onExecutor(executor).map { runtime =>
javaExecutor -> runtime
}
}
.map { iterable =>
val map = iterable.toMap
new HttpRuntime((ctx: Ctx) => map.getOrElse(ctx.executor(), runtime))
}
map += e -> rtm
}

new HttpRuntime((ctx: Ctx) => map.getOrElse(ctx.executor(), rtm))
}

trait Strategy[R] {
Expand Down

0 comments on commit c11a5c1

Please sign in to comment.