pjfanning opened a new pull request, #1927: URL: https://github.com/apache/pekko-connectors/pull/1927
`OAuth2Credentials` materialises a `Source.actorRef` in its constructor to cache and refresh access tokens. Both the completion and failure matchers were `PartialFunction.empty`, so there was no message that could ever stop it, and no API to try. Credentials read through `GoogleExt` are cached per config path per `ActorSystem` and are reclaimed when the system terminates, so the documented paths were never affected. The leak was in the un-cached one: `GoogleSettings(config)` is public, and anyone building credentials per tenant or per request scope got a fresh actor and materialised stream on every call, with no way to release them short of shutting down the actor system. `ServiceAccountCredentials`, `UserAccessCredentials` and `ComputeEngineCredentials` all extend `OAuth2Credentials`, so all three were affected. ### Changes * `Credentials.close()`, a no-op by default. Additive to an `@DoNotInherit` abstract class with a `private[auth]` constructor, so it is binary compatible and cannot clash with a subclass outside the module. * `OAuth2Credentials` overrides it to send a new `Close` command, which the source's completion matcher turns into `CompletionStrategy.draining` — requests already queued are still served rather than left on a promise nothing will complete. * Requests made after close fail with an `IllegalStateException` instead of going to dead letters and hanging forever; `refresh()` becomes a no-op; closing twice has no further effect. `close()` is not automatically wired into `CoordinatedShutdown` — the cached credentials' actors are children of the system and already die with it, so there is nothing to add there. Callers must not use credentials after closing them; that contract is documented on the method and in `google-common.md`. ### Testing Two new cases in `OAuth2CredentialsSpec`: one watches the token stream actor, closes mid-request and asserts both that the queued request is still served and that the actor terminates; the other asserts the post-close failure and that closing twice is safe. Full `google-common/test` passes (26 tests), as does `Test/compile` on Scala 3.3.8 and `checkCodeStyle`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
