Handling Connection Pool Shutdown
- Dominant language
- Scala
- Stars
- 1.4k
- Forks
- 584
- Avg merge
- 14h 33m
- Merged PRs (30d)
- 24
Description
**Issue by [joearasin](https://github.com/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:
``` scala
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:
``` scala
class APIClient(????) {
def getResults: Future[FooServiceResult] = {
Http().singleRequest(...) // How do I ensure the pool that is making these calls gets closed
}
}
```
Contributor guide
Research direction
Start with the Scala example using Http().singleRequest, ActorSystem termination, and the proposed APIClient shape; trace how the connection pool and request stream are shut down. Done means the client lifecycle is clear and terminating the system or closing the pool no longer produces the reported AbruptTerminationException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- api, networking
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100