better handling of resources when responses are handled - #905
Open
pjfanning wants to merge 1 commit into
Open
Conversation
pjfanning
marked this pull request as draft
July 29, 2026 23:48
pjfanning
marked this pull request as ready for review
July 30, 2026 00:30
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
5 files changed, 85 insertions, 42 deletions.
Timeout leak fix: Replaced Future.firstCompletedOf(Seq(strictResponse, timeout)) in makeRequest() with a Promise-based pattern. When the timeout fires first, the onComplete callback on the HTTP response discards the entity via discardEntityBytes(), releasing the connection back to Pekko HTTP's pool. Removed unused pekko.pattern.after import.
Wrong entity fix: Removed entity.discardBytes() in the StatusCodes.Conflict branch of createPodCostResource() — it was discarding the request entity (already sent), not the response (already consumed by toStrict).
Timeout leak fix: Same Promise-based pattern in makeRequest(). The retry wrapper (RetrySupport.retry for 401 token rotation) is preserved — the cleanup runs after the retry chain completes. Removed unused pekko.pattern.after import.
Timeout leak fix: Replaced Future.firstCompletedOf with a Promise-based pattern using scheduleOnce for the timeout and onComplete to cancel it. When the Consul client responds, the timer is cancelled; when the timer fires, the promise fails. Removed unused pekko.pattern.after import.
Timeout leak fix: Replaced Future.firstCompletedOf(List(reply, afterTimeout)) in the ProbeTick handler with a Promise-based pattern. When the timeout fires first, a promise.future.failed.foreach callback discards the in-flight response entity. Removed unused pekko.pattern.after import and replyTimeout val.
Shared timeout fix: Moved the pekko.pattern.after timeout creation inside the checks.map loop so each health check gets its own timer instead of sharing one. Eliminates the timeout.recoverWith wrapper that enriched the generic RuntimeException — the timeout now throws CheckTimeoutException directly.
Pattern Used
All HTTP-based modules use the same cleanup pattern:
This ensures the HTTP response entity is always consumed — either by the normal processing path, or by discardEntityBytes() if the timeout won the race.