akka/akka-http

Handling Connection Pool Shutdown

Offen

#83 geöffnet am 08.09.2016

 (5 Kommentare) (1 Reaktion) (0 zugewiesene Personen)Scala (598 Forks)batch import
1 - triagedhelp wantednice-to-have (low-prio)t:client

Repository-Metriken

Stars
 (1.311 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 1T 10h) (2 gemergte PRs in 30 T)

Beschreibung

Issue by joearasin Thursday Feb 25, 2016 at 23:32 GMT Originally opened as https://github.com/akka/akka/issues/19884


If I run code that looks like:

object Test extends App {
  implicit val system = ActorSystem()
  implicit val mat: ActorMaterializer = ActorMaterializer()
  implicit val ec = mat.executionContext
  val result: Future[HttpResponse] = Http().singleRequest(HttpRequest(uri = "http://www.google.com"))

  result.flatMap { case response: HttpResponse =>
    Unmarshal(response.entity).to[String]
  }.flatMap{ case body: String =>
    println(body)
    system.terminate()
  }.onFailure { case e: Throwable =>
    println(e)
    println("Something went wrong")
  }
}

It works, but I get a [ERROR] [02/25/2016 18:13:41.930] [default-akka.actor.default-dispatcher-11] [akka.actor.ActorSystemImpl(default)] Outgoing request stream error (akka.stream.AbruptTerminationException)

This can be avoided if I shutdown the connection pool.

When attempting to build an API client that uses Akka-HTTP internally, I'm trying to figure out what the proper way to either handle the pool internally, or expose something that makes it clear to the calling code that something was opened, and thus needs to be closed, or maybe the error shouldn't occur altogether.

Ideally, I want to have an API client that looks something like:

class APIClient(????) {
   def getResults: Future[FooServiceResult] = {
     Http().singleRequest(...) // How do I ensure the pool that is making these calls gets closed
   }
}

Contributor Guide