akka/akka-http

Handling Connection Pool Shutdown

開放

#83 建立於 2016年9月8日

 (5 則留言) (1 個反應) (0 位負責人)Scala (598 個分叉)batch import
1 - triagedhelp wantednice-to-have (low-prio)t:client

倉庫指標

星標
 (1,311 顆星)
PR 合併指標
 (平均合併 1天 10小時) (30 天內合併 2 個 PR)

描述

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
   }
}

貢獻者指南