1

I'm learning http4s and trying out the basic example from the documentation, and I've noticed something weird. Simply starting and stopping the server works fine, but if any requests are sent, a graceful shutdown takes about 30 seconds (during which new incoming requests are still processed and responded to).

This is the code:

object Main extends IOApp.Simple {
  val helloWorldService = HttpRoutes.of[IO] {
    case GET -> Root / "hello" / name =>
      Ok(s"Hello, $name.")
  }.orNotFound

  def server[F[_] : Async : Network]: EmberServerBuilder[F] = {
    EmberServerBuilder
      .default[F]
      .withHost(ipv4"0.0.0.0")
      .withPort(port"8000")
  }

  def run: IO[Unit] = {
    server[IO]
      .withHttpApp(helloWorldService)
      .build
      .use(_ => IO.never)
  }
}

This happens on both the stable (0.23.16) and dev (1.0.0-M37) versions.

Modus Operandi
  • 552
  • 1
  • 6
  • 24
  • Two things, one is that it would be great to know the exact versions you are using and how exactly you are running the code. The second is that you probably can get better help in the official **Discord** server: https://discord.com/channels/632277896739946517/632286375311573032 – Luis Miguel Mejía Suárez Dec 01 '22 at 15:18
  • I edited the question and added http4s version. I run on a Windows machine, the same thing happens in both IntellijIDEA and running a compiled .jar from the command line. I tried the discord link, and all I got was "you have no access to any text channels or there are none on this server". I'll see if the Discord link on the http4s website works any better. – Modus Operandi Dec 01 '22 at 16:00

1 Answers1

1

Turns out the cause was the browser/Postman keeping the connection alive. Simply closing Postman after the request closed the connection and the shutdown was immediate.

And EmberServerBuilder has .withShutdownTimeout setting to control how long the shutdown waits for connections to be closed.

Modus Operandi
  • 552
  • 1
  • 6
  • 24