Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't add ResponseHeaderTimeoutStage on infinite timeout #2761

Merged
merged 2 commits into from Aug 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -112,27 +112,31 @@ object BlazeClient {
}
}

Deferred[F, Unit].flatMap { gate =>
val responseHeaderTimeoutF: F[TimeoutException] =
F.delay {
val stage =
new ResponseHeaderTimeoutStage[ByteBuffer](
responseHeaderTimeout,
scheduler,
ec)
next.connection.spliceBefore(stage)
stage
}
.bracket(stage =>
F.asyncF[TimeoutException] { cb =>
F.delay(stage.init(cb)) >> gate.complete(())
})(stage => F.delay(stage.removeStage()))
responseHeaderTimeout match {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scalafmt made this look bigger than it is. In short, just return the response if there's nothing finite to race against.

case responseHeaderTimeout: FiniteDuration =>
Deferred[F, Unit].flatMap { gate =>
val responseHeaderTimeoutF: F[TimeoutException] =
F.delay {
val stage =
new ResponseHeaderTimeoutStage[ByteBuffer](
responseHeaderTimeout,
scheduler,
ec)
next.connection.spliceBefore(stage)
stage
}
.bracket(stage =>
F.asyncF[TimeoutException] { cb =>
F.delay(stage.init(cb)) >> gate.complete(())
})(stage => F.delay(stage.removeStage()))

F.racePair(gate.get *> res, responseHeaderTimeoutF)
.flatMap[Resource[F, Response[F]]] {
case Left((r, fiber)) => fiber.cancel.as(r)
case Right((fiber, t)) => fiber.cancel >> F.raiseError(t)
F.racePair(gate.get *> res, responseHeaderTimeoutF)
.flatMap[Resource[F, Response[F]]] {
case Left((r, fiber)) => fiber.cancel.as(r)
case Right((fiber, t)) => fiber.cancel >> F.raiseError(t)
}
}
case _ => res
}
}
}
Expand Down
Expand Up @@ -8,10 +8,10 @@ import org.http4s.blaze.util.{Cancelable, TickWheelExecutor}
import org.log4s.getLogger
import scala.annotation.tailrec
import scala.concurrent.{ExecutionContext, Future}
import scala.concurrent.duration.Duration
import scala.concurrent.duration.FiniteDuration

final private[http4s] class ResponseHeaderTimeoutStage[A](
timeout: Duration,
timeout: FiniteDuration,
exec: TickWheelExecutor,
ec: ExecutionContext)
extends MidStage[A, A] { stage =>
Expand Down Expand Up @@ -52,7 +52,7 @@ final private[http4s] class ResponseHeaderTimeoutStage[A](

override def stageStartup(): Unit = {
super.stageStartup()
logger.debug(s"Starting response header timeout stage with timeout of ${timeout.toMillis} ms")
logger.debug(s"Starting response header timeout stage with timeout of ${timeout}")
}

def init(cb: Callback[TimeoutException]): Unit = {
Expand Down
5 changes: 5 additions & 0 deletions build.sbt
@@ -1,3 +1,4 @@
import com.typesafe.tools.mima.core._
import org.http4s.build.Http4sPlugin._
import scala.xml.transform.{RewriteRule, RuleTransformer}

Expand Down Expand Up @@ -192,6 +193,10 @@ lazy val blazeCore = libraryProject("blaze-core")
.settings(
description := "Base library for binding blaze to http4s clients and servers",
libraryDependencies += blaze,
mimaBinaryIssueFilters ++= List(
// Private API
ProblemFilters.exclude[IncompatibleMethTypeProblem]("org.http4s.blazecore.ResponseHeaderTimeoutStage.this")
),
)
.dependsOn(core, testing % "test->test")

Expand Down