Skip to content

fix: close OkHttp response bodies to prevent connection leaks#237

Merged
nicklasl merged 3 commits intomainfrom
fix/close-okhttp-response-bodies
Mar 26, 2026
Merged

fix: close OkHttp response bodies to prevent connection leaks#237
nicklasl merged 3 commits intomainfrom
fix/close-okhttp-response-bodies

Conversation

@fabriziodemaria
Copy link
Copy Markdown
Member

Summary

  • Wraps OkHttp Response objects in .use {} blocks across all HTTP call sites to ensure response bodies are always closed, fixing the "A connection to https://resolver.eu.confidence.dev/ was leaked" warning.
  • FlagApplierClientImpl: Response from applyInteractor.invoke() was never closed.
  • EventSenderUploaderImpl: Response from event upload was never closed.
  • RemoteFlagResolver: Replaced manual body.close() in a finally block with Response.use {} for safer, simpler cleanup.

Test plan

  • Run the demo app and verify the OkHttp connection leak warning no longer appears in logcat
  • Verify flag resolution, flag apply, and event upload still work correctly

Made with Cursor

Use Response.use {} to ensure OkHttp response bodies are always closed,
preventing "connection was leaked" warnings. Affected call sites:
- FlagApplierClientImpl (flags:apply)
- EventSenderUploaderImpl (events:publish)
- RemoteFlagResolver (flags:resolve)

Made-with: Cursor
fabriziodemaria and others added 2 commits March 25, 2026 23:11
Previously, toResolveFlags() would log the error but still attempt to
deserialize the response body on HTTP errors, leading to confusing
parse exceptions. Now it throws immediately with the HTTP status code.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…onses

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Member

@nicklasl nicklasl left a comment

Choose a reason for hiding this comment

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

Added a small adjustment (introduced a http error exception)

@nicklasl nicklasl merged commit 40d014b into main Mar 26, 2026
2 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.

2 participants