Skip to content

Add missing resource variants that close a user-provided client - #2978

Merged
adamw merged 3 commits into
softwaremill:masterfrom
mmustafasenoglu:feat/closefactory-param
Sep 25, 2026
Merged

adamw merged 3 commits into
softwaremill:masterfrom
mmustafasenoglu:feat/closefactory-param

Conversation

@mmustafasenoglu

@mmustafasenoglu mmustafasenoglu commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

A client passed to usingClient is never closed, same as in all other backends. To let the backend close a user-provided client, use resourceUsingClient / scopedUsingClient / managedUsingClient. This adds these variants where they were missing:

  • ArmeriaMonixBackend: resource, resourceUsingClient
  • ArmeriaZioBackend (zio1): managedUsingClient
  • OkHttpMonixBackend: resourceUsingClient
  • HttpClientZioBackend (zio1): managedUsingClient

Behavior change: HttpClientZioBackend.layerUsingClient (zio, zio1) now closes the client when the layer is released, like scopedUsingClient. In zio1 it never closed the client before, because ZManaged.makeEffect didn't run the release effect.

Closes #2628

…ultClient

The usingClient and usingDefaultClient factory methods on Armeria and
OkHttp backends hardcoded closeFactory/closeClient to false, giving
users no way to have the backend close a user-provided client.

This adds an optional closeFactory/closeClient: Boolean = false parameter
to all public factory methods, allowing users to control whether the
backend should close the underlying client on backend.close().

Armeria backends (9 files):
- ArmeriaCatsBackend (CE3 + CE2)
- ArmeriaFutureBackend
- ArmeriaFs2Backend (CE3 + CE2)
- ArmeriaZioBackend (ZIO 2 + ZIO 1)
- ArmeriaMonixBackend
- ArmeriaScalazBackend

OkHttp backends (2 files):
- OkHttpSyncBackend
- OkHttpFutureBackend

Closes softwaremill#2628
Copilot AI lite review requested due to automatic review settings August 24, 2026 15:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@adamw

adamw commented Aug 25, 2026

Copy link
Copy Markdown
Member

Thanks - although compilation fails in a number of cases

Reverts the closeFactory/closeClient parameters. A client passed to
usingClient is never closed, as in all other backends. To let the
backend close a user-provided client, use the resource variant:

- ArmeriaMonixBackend: add resource and resourceUsingClient
- ArmeriaZioBackend (zio1): add managedUsingClient
- OkHttpMonixBackend: add resourceUsingClient
- HttpClientZioBackend (zio, zio1): layerUsingClient now closes the
  client, like scopedUsingClient; zio1 gets managedUsingClient
@adamw adamw changed the title feat: add closeFactory/closeClient parameter to usingClient/usingDefaultClient Add missing resource variants that close a user-provided client Sep 25, 2026
@adamw
adamw merged commit 7e7c005 into softwaremill:master Sep 25, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Confusing ArmeriaCatsBackend initialization

3 participants