sttp icon indicating copy to clipboard operation
sttp copied to clipboard

Confusing ArmeriaCatsBackend initialization

Open Awethon opened this issue 5 months ago • 1 comments

ArmeriaCatsBackend can be created with apply and then closeFactory will be true, but if it is created with usingClient or usingDefaultClient then closeFactory isfalse.

I don't know how to interpret it and what was the motivation behind it.

What I wanted to do is to create a method that would return SttpBackend with all the needed decorations of WebClient, but it's only possible to do it with usingClient which has closeFactory set to false.

And there's currently no workaround for it, because both constructor and apply method are private

Awethon avatar Aug 05 '25 10:08 Awethon

I think the assumption is that if you are managing the WebClient instance yourself, you are also responsible for closing it. It's the same across other backends (not only Armeria-based) as far as I'm aware.

A work-around might be to create a backend wrapper which additionally does the necessary cleanup as part of its close(), and otherwise delegates all other method calls.

You can also propose a PR which adds a variant of these methods with the closeFactory flag - to this, and other backends?

adamw avatar Aug 11 '25 13:08 adamw