The GitHub Actions job "Scalafmt" on 
pekko-management.git/aws-async-client-shutdown has failed.
Run started by GitHub user pjfanning (triggered by pjfanning).

Head commit for run:
99413e63fa552297b8824255a3390d922a9be6ff / PJ Fanning 
<[email protected]>
Close the async ECS discovery clients on coordinated shutdown

Motivation:
#907 gave the deprecated `pekko-discovery-aws-api` module a CoordinatedShutdown
task that closes its AWS SDK v1 clients, but left 
`pekko-discovery-aws-api-async`
- the module users are told to migrate to - untouched. Both
`AsyncEcsServiceDiscovery` and `AsyncEcsTaskSetDiscovery` build an
`EcsAsyncClient` and never close it.

The leak is larger there than in the module that was fixed.
`AsyncEcsServiceDiscovery` passes `NettyNioAsyncHttpClient.create()` to
`.httpClient(...)`, which the SDK treats as caller-owned and wraps so that
`close()` is a no-op, so its event loop threads outlive the ActorSystem even if
the ECS client were closed.

Modification:
Give both classes an `AtomicReference` that is populated only after the client
has been built, and a `PhaseServiceUnbind` task that closes whatever client it
finds there and does nothing when it is null - so shutdown never forces, or
re-attempts, the lazy initialisation. The close runs on
`pekko.actor.default-blocking-io-dispatcher` because it blocks until the
underlying HTTP client has shut down.

Switch `AsyncEcsServiceDiscovery` from `.httpClient(NettyNioAsyncHttpClient
.create())` to `.httpClientBuilder(NettyNioAsyncHttpClient.builder())` so the
SDK owns the Netty client and shuts down its event loops when the ECS client is
closed.

Client construction moves behind `private[ecs] def createEcsClient()` so the new
spec can supply a stub without AWS credentials, a region, or network access.

Result:
Terminating the ActorSystem releases the ECS clients and their Netty event loop
threads. Discovery that is configured but never used still creates no client.

Tests:
- sbt "discovery-aws-api-async/test" - 4 succeeded, 0 failed (new
  AsyncEcsClientShutdownSpec; this module had no test sources before)
- sbt "discovery-aws-api-async/mimaReportBinaryIssues" - success
- sbt "discovery-aws-api-async/scalafmt"
  "discovery-aws-api-async/Test/scalafmt", sbt headerCreateAll - clean
- Not run against live AWS - no account available; the spec stubs 
EcsAsyncClient.

References:
Refs #907

Report URL: https://github.com/apache/pekko-management/actions/runs/32873222450

With regards,
GitHub Actions via GitBox


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to