Skip to content

Instantly share code, notes, and snippets.

@BalmungSan
Last active January 14, 2020 20:30
Show Gist options
  • Save BalmungSan/99978e5d699575f19b8cbcc608032a05 to your computer and use it in GitHub Desktop.
Save BalmungSan/99978e5d699575f19b8cbcc608032a05 to your computer and use it in GitHub Desktop.
Stacktrace produced when attempting to gracefully stop an ember server
// Project settings.
name := "ember-crash"
organization := "co.com.psl"
organizationName := "PSL S.A.S."
organizationHomepage := Some(url("http://www.psl.com.co/"))
version := "0.1.0"
scalaVersion := "2.13.1"
// Kind projector.
addCompilerPlugin("org.typelevel" %% "kind-projector" % "0.11.0" cross CrossVersion.full)
scalacOptions += "-Dkp:genAsciiNames=true"
// Better monadic for.
addCompilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.0")
// Application dependencies.
val CatsEffectVersion = "2.0.0"
val CatsVersion = "2.1.0"
val Fs2Version = "2.1.0"
val Http4sVersion = "0.21.0-M6"
val LogbackClassicVersion = "1.2.3"
libraryDependencies ++= Seq(
"ch.qos.logback" % "logback-classic" % LogbackClassicVersion,
"co.fs2" %% "fs2-core" % Fs2Version,
"co.fs2" %% "fs2-io" % Fs2Version,
"org.http4s" %% "http4s-ember-server" % Http4sVersion,
"org.http4s" %% "http4s-core" % Http4sVersion,
"org.http4s" %% "http4s-circe" % Http4sVersion,
"org.http4s" %% "http4s-dsl" % Http4sVersion,
"org.typelevel" %% "cats-core" % CatsVersion,
"org.typelevel" %% "cats-effect" % CatsEffectVersion
)
java.util.concurrent.RejectedExecutionException: Task cats.effect.internals.IOShift$Tick@1d4aa74b rejected from java.util.concurrent.ThreadPoolExecutor@3a57c4b4[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 3]
at java.base/java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2055)
at java.base/java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:825)
at java.base/java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1355)
at scala.concurrent.impl.ExecutionContextImpl.execute(ExecutionContextImpl.scala:21)
at cats.effect.internals.IOShift$$anon$1.apply(IOShift.scala:28)
at cats.effect.internals.IOShift$$anon$1.apply(IOShift.scala:26)
at cats.effect.internals.IORunLoop$RestartCallback.start(IORunLoop.scala:341)
at cats.effect.internals.IORunLoop$.cats$effect$internals$IORunLoop$$loop(IORunLoop.scala:119)
at cats.effect.internals.IORunLoop$.start(IORunLoop.scala:34)
at cats.effect.internals.IOBracket$.$anonfun$apply$1(IOBracket.scala:44)
at cats.effect.internals.IOBracket$.$anonfun$apply$1$adapted(IOBracket.scala:34)
at cats.effect.internals.IORunLoop$RestartCallback.start(IORunLoop.scala:341)
at cats.effect.internals.IORunLoop$.cats$effect$internals$IORunLoop$$loop(IORunLoop.scala:119)
at cats.effect.internals.IORunLoop$RestartCallback.signal(IORunLoop.scala:355)
at cats.effect.internals.IORunLoop$RestartCallback.run(IORunLoop.scala:366)
at cats.effect.internals.Trampoline.cats$effect$internals$Trampoline$$immediateLoop(Trampoline.scala:70)
at cats.effect.internals.Trampoline.startLoop(Trampoline.scala:36)
at cats.effect.internals.TrampolineEC$JVMTrampoline.super$startLoop(TrampolineEC.scala:93)
at cats.effect.internals.TrampolineEC$JVMTrampoline.$anonfun$startLoop$1(TrampolineEC.scala:93)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:94)
at cats.effect.internals.TrampolineEC$JVMTrampoline.startLoop(TrampolineEC.scala:93)
at cats.effect.internals.Trampoline.execute(Trampoline.scala:43)
at cats.effect.internals.TrampolineEC.execute(TrampolineEC.scala:44)
at cats.effect.internals.IORunLoop$RestartCallback.apply(IORunLoop.scala:374)
at cats.effect.internals.IORunLoop$RestartCallback.apply(IORunLoop.scala:316)
at cats.effect.internals.IORace$.$anonfun$simple$1(IORace.scala:42)
at cats.effect.internals.IORace$.$anonfun$simple$1$adapted(IORace.scala:40)
at cats.effect.internals.IORunLoop$.cats$effect$internals$IORunLoop$$loop(IORunLoop.scala:136)
at cats.effect.internals.IORunLoop$RestartCallback.signal(IORunLoop.scala:355)
at cats.effect.internals.IORunLoop$RestartCallback.apply(IORunLoop.scala:376)
at cats.effect.internals.IORunLoop$RestartCallback.apply(IORunLoop.scala:316)
at cats.effect.internals.IOShift$Tick.run(IOShift.scala:36)
at cats.effect.internals.PoolUtils$$anon$2$$anon$3.run(PoolUtils.scala:51)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
import cats.effect.{ExitCode, IO, IOApp, Resource}
import cats.implicits._
import fs2.Stream
import org.http4s.{HttpApp, HttpRoutes}
import org.http4s.ember.server.EmberServerBuilder
import org.http4s.server.{Router, Server}
import org.http4s.syntax.kleisli._
object Main extends IOApp {
private val service: HttpRoutes[IO] = {
import org.http4s.dsl.io._
HttpRoutes.of[IO] {
case GET -> Root / "hello" => Ok("Hello")
}
}
val app: HttpApp[IO] =
Router(
"/" -> service
).orNotFound
private val server: Resource[IO, Server[IO]] =
EmberServerBuilder
.default[IO]
.withHost("0.0.0.0")
.withPort(8080)
.withHttpApp(app)
.build
private val program: Stream[IO, Unit] =
for {
server <- Stream.resource(server)
_ <- Stream.eval(IO(println(s"Started server on: ${server.address}")))
_ <- Stream.never[IO].covaryOutput[Unit]
} yield ()
override def run(args: List[String]): IO[ExitCode] =
program.compile.drain.as(ExitCode.Success)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment