Skip to content

Instantly share code, notes, and snippets.

@Pyppe
Last active October 19, 2018 11:40
Show Gist options
  • Save Pyppe/14dba517cf3c97c270589fe4ac41f838 to your computer and use it in GitHub Desktop.
Save Pyppe/14dba517cf3c97c270589fe4ac41f838 to your computer and use it in GitHub Desktop.

So we have a server running on localhost:8080.

  • Calling it with curl 'localhost:8080/foo/ping' works fine, and no timeouts are shown.
  • If I open the page in Chrome however, I get the response fine, but after timeout-threshold (2 sec in this example) the logs get a lot of errors:
    • EDIT: If I use Chrome's Incognito mode; no timeouts errors then
[info] java.util.concurrent.TimeoutException: Timeout of 2 seconds triggered. Killing pipeline.
[info] 	at org.http4s.blaze.pipeline.stages.TimeoutStageBase$$anon$1.run(TimeoutStageBase.scala:29)
[info] 	at org.http4s.blaze.util.Execution$$anon$3.execute(Execution.scala:66)
[info] 	at org.http4s.blaze.util.TickWheelExecutor$Node.run(TickWheelExecutor.scala:261)
[info] 	at org.http4s.blaze.util.TickWheelExecutor$Bucket.checkNext$1(TickWheelExecutor.scala:193)
[info] 	at org.http4s.blaze.util.TickWheelExecutor$Bucket.prune(TickWheelExecutor.scala:200)
[info] 	at org.http4s.blaze.util.TickWheelExecutor.go$3(TickWheelExecutor.scala:153)
[info] 	at org.http4s.blaze.util.TickWheelExecutor.org$http4s$blaze$util$TickWheelExecutor$$cycle(TickWheelExecutor.scala:156)
[info] 	at org.http4s.blaze.util.TickWheelExecutor$$anon$1.run(TickWheelExecutor.scala:55)
[info] 14:03:47.588 [blaze-selector-0-3] ERROR o.h.blaze.channel.nio1.NIO1HeadStage - Abnormal NIO1HeadStage termination
[info] java.util.concurrent.TimeoutException: Timeout of 2 seconds triggered. Killing pipeline.
[info] 	at org.http4s.blaze.pipeline.stages.TimeoutStageBase$$anon$1.run(TimeoutStageBase.scala:29)
[info] 	at org.http4s.blaze.util.Execution$$anon$3.execute(Execution.scala:66)
[info] 	at org.http4s.blaze.util.TickWheelExecutor$Node.run(TickWheelExecutor.scala:261)
[info] 	at org.http4s.blaze.util.TickWheelExecutor$Bucket.checkNext$1(TickWheelExecutor.scala:193)
[info] 	at org.http4s.blaze.util.TickWheelExecutor$Bucket.prune(TickWheelExecutor.scala:200)
[info] 	at org.http4s.blaze.util.TickWheelExecutor.go$3(TickWheelExecutor.scala:153)
[info] 	at org.http4s.blaze.util.TickWheelExecutor.org$http4s$blaze$util$TickWheelExecutor$$cycle(TickWheelExecutor.scala:156)
[info] 	at org.http4s.blaze.util.TickWheelExecutor$$anon$1.run(TickWheelExecutor.scala:55)
[info] 14:03:47.589 [blaze-selector-0-4] ERROR o.h.s.blaze.Http1ServerStage$$anon$1 - Fatal Error: Error in requestLoop()
[info] java.util.concurrent.TimeoutException: Timeout of 2 seconds triggered. Killing pipeline.
[info] 	at org.http4s.blaze.pipeline.stages.TimeoutStageBase$$anon$1.run(TimeoutStageBase.scala:29)
[info] 	at org.http4s.blaze.util.Execution$$anon$3.execute(Execution.scala:66)
[info] 	at org.http4s.blaze.util.TickWheelExecutor$Node.run(TickWheelExecutor.scala:261)
[info] 	at org.http4s.blaze.util.TickWheelExecutor$Bucket.checkNext$1(TickWheelExecutor.scala:193)
[info] 	at org.http4s.blaze.util.TickWheelExecutor$Bucket.prune(TickWheelExecutor.scala:200)
[info] 	at org.http4s.blaze.util.TickWheelExecutor.go$3(TickWheelExecutor.scala:153)
[info] 	at org.http4s.blaze.util.TickWheelExecutor.org$http4s$blaze$util$TickWheelExecutor$$cycle(TickWheelExecutor.scala:156)
[info] 	at org.http4s.blaze.util.TickWheelExecutor$$anon$1.run(TickWheelExecutor.scala:55)
[info] 14:03:47.589 [blaze-selector-0-3] ERROR o.h.s.blaze.Http1ServerStage$$anon$1 - Fatal Error: Error in requestLoop()
[info] java.util.concurrent.TimeoutException: Timeout of 2 seconds triggered. Killing pipeline.
[info] 	at org.http4s.blaze.pipeline.stages.TimeoutStageBase$$anon$1.run(TimeoutStageBase.scala:29)
[info] 	at org.http4s.blaze.util.Execution$$anon$3.execute(Execution.scala:66)
[info] 	at org.http4s.blaze.util.TickWheelExecutor$Node.run(TickWheelExecutor.scala:261)
[info] 	at org.http4s.blaze.util.TickWheelExecutor$Bucket.checkNext$1(TickWheelExecutor.scala:193)
[info] 	at org.http4s.blaze.util.TickWheelExecutor$Bucket.prune(TickWheelExecutor.scala:200)
[info] 	at org.http4s.blaze.util.TickWheelExecutor.go$3(TickWheelExecutor.scala:153)
[info] 	at org.http4s.blaze.util.TickWheelExecutor.org$http4s$blaze$util$TickWheelExecutor$$cycle(TickWheelExecutor.scala:156)
[info] 	at org.http4s.blaze.util.TickWheelExecutor$$anon$1.run(TickWheelExecutor.scala:55)
[info] 14:03:47.589 [blaze-selector-0-3] ERROR o.h.blaze.channel.nio1.NIO1HeadStage - Abnormal NIO1HeadStage termination
[info] java.util.concurrent.TimeoutException: Timeout of 2 seconds triggered. Killing pipeline.
[info] 	at org.http4s.blaze.pipeline.stages.TimeoutStageBase$$anon$1.run(TimeoutStageBase.scala:29)
[info] 	at org.http4s.blaze.util.Execution$$anon$3.execute(Execution.scala:66)
[info] 	at org.http4s.blaze.util.TickWheelExecutor$Node.run(TickWheelExecutor.scala:261)
[info] 	at org.http4s.blaze.util.TickWheelExecutor$Bucket.checkNext$1(TickWheelExecutor.scala:193)
[info] 	at org.http4s.blaze.util.TickWheelExecutor$Bucket.prune(TickWheelExecutor.scala:200)
[info] 	at org.http4s.blaze.util.TickWheelExecutor.go$3(TickWheelExecutor.scala:153)
[info] 	at org.http4s.blaze.util.TickWheelExecutor.org$http4s$blaze$util$TickWheelExecutor$$cycle(TickWheelExecutor.scala:156)
[info] 	at org.http4s.blaze.util.TickWheelExecutor$$anon$1.run(TickWheelExecutor.scala:55)
[info] 14:03:47.589 [blaze-selector-0-4] ERROR o.h.blaze.channel.nio1.NIO1HeadStage - Abnormal NIO1HeadStage termination
[info] java.util.concurrent.TimeoutException: Timeout of 2 seconds triggered. Killing pipeline.
[info] 	at org.http4s.blaze.pipeline.stages.TimeoutStageBase$$anon$1.run(TimeoutStageBase.scala:29)
[info] 	at org.http4s.blaze.util.Execution$$anon$3.execute(Execution.scala:66)
[info] 	at org.http4s.blaze.util.TickWheelExecutor$Node.run(TickWheelExecutor.scala:261)
[info] 	at org.http4s.blaze.util.TickWheelExecutor$Bucket.checkNext$1(TickWheelExecutor.scala:193)
[info] 	at org.http4s.blaze.util.TickWheelExecutor$Bucket.prune(TickWheelExecutor.scala:200)
[info] 	at org.http4s.blaze.util.TickWheelExecutor.go$3(TickWheelExecutor.scala:153)
[info] 	at org.http4s.blaze.util.TickWheelExecutor.org$http4s$blaze$util$TickWheelExecutor$$cycle(TickWheelExecutor.scala:156)
[info] 	at org.http4s.blaze.util.TickWheelExecutor$$anon$1.run(TickWheelExecutor.scala:55)
package com.example.http4s.blaze
import cats.effect.IO
import java.util.concurrent.CountDownLatch
import org.http4s.HttpRoutes
import org.http4s.server.blaze.BlazeServerBuilder
import org.http4s.dsl.io._
import org.http4s.server.Router
import scala.concurrent.ExecutionContext
import scala.concurrent.duration._
object SimpleBlazeServer {
implicit val cs = IO.contextShift(ExecutionContext.Implicits.global)
val shutdownLatch = new CountDownLatch(1)
def main(args: Array[String]): Unit = {
val services = List(
"/foo" -> HttpRoutes.of[IO] {
case GET -> Root / "ping" => Ok("pong")
}
)
val routes = Router[IO](services: _*)
BlazeServerBuilder[IO].
bindHttp(8080, "0.0.0.0").
withIdleTimeout(2.seconds).
withHttpApp(routes.orNotFound).
resource.
use(_ => IO.never).
start.
unsafeRunSync()
shutdownLatch.await()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment