Skip to content

docs: clarify close ownership when a recovery step turns a Success into a Failure#131

Merged
OmarAlJarrah merged 1 commit into
mainfrom
docs/recovery-pipeline-close-ownership
Jun 17, 2026
Merged

docs: clarify close ownership when a recovery step turns a Success into a Failure#131
OmarAlJarrah merged 1 commit into
mainfrom
docs/recovery-pipeline-close-ownership

Conversation

@OmarAlJarrah

Copy link
Copy Markdown
Member

Problem

The recovery-aware ResponsePipeline lets a step transform a ResponseOutcome.Success into a Failure (e.g. status-to-typed-exception mapping) or substitute a different Success. The original successful Response holds an open transport connection / body stream, but until now nothing documented who is responsible for closing it on that transform path. The actual behavior was easy to misread: it is tempting to assume the pipeline drains/closes any response it stops surfacing.

Actual behavior (now documented)

The ResponsePipeline closes the in-hand Success response on exactly one path: when a step throws while holding it. Both the success-path (applyResponseSteps) and the recovery chain (invokeRecovery) close-before-propagate and attach any close error to the step's throwable as suppressed.

It does not close the response when a step is handed a Success and deliberately returns a different outcome — a Success → Failure transform or a substitute Success. The pipeline never observes the dropped response, so the step that performs the transform owns closing the response it discards (outcome.response.close() before returning the replacement), or the connection leaks. The Failure(t1) → Failure(t2) "Replace" path carries no response, so there is nothing to close there.

Change

Documentation only:

  • ResponseRecoveryStep KDoc — new "Close ownership when discarding a Success" section.
  • ResponsePipeline KDoc — new "Close ownership of a discarded Success response" section describing the throw-only close path.
  • docs/pipelines.md — matching subsection under the ResponsePipeline description.

No code behavior changes; :sdk-core compile, ktlint, detekt, and apiCheck pass.

Closes #110

…sform

When a response or recovery step is handed a ResponseOutcome.Success and
deliberately returns a different outcome (e.g. a status-to-typed-exception
mapping that produces a Failure, or a substitute Success), the original
successful Response is discarded. The ResponsePipeline only closes the in-hand
response when a step throws while holding it; on the return-a-different-outcome
path it never observes the dropped response and does not close it.

Document that the step performing the transform owns closing the response it
discards, in the KDoc of ResponseRecoveryStep and ResponsePipeline and in
docs/pipelines.md.

Closes #110
@OmarAlJarrah OmarAlJarrah merged commit b470df2 into main Jun 17, 2026
1 check passed
@OmarAlJarrah OmarAlJarrah deleted the docs/recovery-pipeline-close-ownership branch June 17, 2026 01:54
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.

ResponseRecoveryStep close-ownership for the Success→Failure transform path is undocumented

1 participant