Skip to content

chore: Implement AutoCloseable and close() lifecycle for ScalekitClient and ScalekitAuthClient #65

Description

@coderabbitai

Summary

Add explicit resource cleanup lifecycle (AutoCloseable / close()) to ScalekitClient and ScalekitAuthClient for correctness in non-singleton / short-lived usage scenarios.

Background

Flagged in PR #64 (#64 (comment)) during the HTTP connection eviction and gRPC keepalive fix.

Currently, ScalekitClient is intentionally used as a long-lived application-lifetime singleton, so OS reclaims resources on JVM exit. However, explicit lifecycle management is a best practice for SDK clients and would support:

  • Short-lived or scoped usage (e.g., in tests or serverless contexts)
  • Integration with DI frameworks (Spring, Guice) that manage bean lifecycles
  • Preventing resource retention in container environments with multiple reloads

Tasks

  • Make ScalekitAuthClient implement AutoCloseable; add close() that calls httpClient.close() and shuts down the underlying PoolingHttpClientConnectionManager
  • Store the ManagedChannel instance in a private field in ScalekitClient instead of a local variable
  • Make ScalekitClient implement AutoCloseable; add close() that shuts down the gRPC channel and closes the auth client

Requested by

@Avinash-Kamath

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions