Skip to content

fix: reuse HttpClient instance across authorize() calls#143

Merged
maltesander merged 4 commits intostackabletech:mainfrom
vikshab:bug_fix_reuse_http_client_in_opa_authorizer
Apr 2, 2026
Merged

fix: reuse HttpClient instance across authorize() calls#143
maltesander merged 4 commits intostackabletech:mainfrom
vikshab:bug_fix_reuse_http_client_in_opa_authorizer

Conversation

@vikshab
Copy link
Copy Markdown
Contributor

@vikshab vikshab commented Mar 28, 2026

Fixes #142 issue

Problem

Each call to OpaAuthorizer.authorize() creates a new HttpClient via HttpClient.newHttpClient(). Every HttpClient spawns a SelectorManager background thread and its own connection pool that are never shut down, causing unbounded thread growth under load.

Fix

Move HttpClient to an instance field initialized once in the constructor. HttpClient is thread-safe and designed to be reused — a single instance handles all concurrent requests via its internal connection pool, eliminating the thread leak

Creating a new HttpClient on every authorize() call spawns a new
SelectorManager thread each time, causing thread exhaustion under load.
HttpClient is thread-safe and designed to be reused — move it to an
instance field initialized once in the constructor.
@stackable-cla
Copy link
Copy Markdown

stackable-cla bot commented Mar 28, 2026

CLA assistant check
All committers have signed the CLA.

@maltesander
Copy link
Copy Markdown
Member

Hi @vikshab,

thank you, LGTM, would you mind adding a changelog entry under "unreleased" and a new section "### Fixed" ?

I can do it as well.

Malte

@maltesander maltesander self-requested a review March 30, 2026 07:09
@vikshab
Copy link
Copy Markdown
Contributor Author

vikshab commented Mar 30, 2026

Hi @vikshab,

thank you, LGTM, would you mind adding a changelog entry under "unreleased" and a new section "### Fixed" ?

I can do it as well.

Malte

@maltesander Pushed new commit

@maltesander
Copy link
Copy Markdown
Member

Hey thank you, but this is in the wrong place. I meant something like this (from the top):

# Changelog

## [Unreleased]

### Added

- Add support for Druid 35.0.1 ([#138]).
- Add support for Druid 34.0.0 (deprecated) ([#134], [#138]).

### Fixed

- Reuse HttpClient instance across authorize() calls ([#143]).

### Removed

- Remove support for Druid 33.0.0 ([#138]).
- Remove support for Druid 31.0.1 ([#134]).

[#134]: https://github.com/stackabletech/druid-opa-authorizer/pull/134
[#138]: https://github.com/stackabletech/druid-opa-authorizer/pull/138
[#143]: https://github.com/stackabletech/druid-opa-authorizer/pull/143

@vikshab
Copy link
Copy Markdown
Contributor Author

vikshab commented Apr 1, 2026

Hey thank you, but this is in the wrong place. I meant something like this (from the top):

# Changelog

## [Unreleased]

### Added

- Add support for Druid 35.0.1 ([#138]).
- Add support for Druid 34.0.0 (deprecated) ([#134], [#138]).

### Fixed

- Reuse HttpClient instance across authorize() calls ([#143]).

### Removed

- Remove support for Druid 33.0.0 ([#138]).
- Remove support for Druid 31.0.1 ([#134]).

[#134]: https://github.com/stackabletech/druid-opa-authorizer/pull/134
[#138]: https://github.com/stackabletech/druid-opa-authorizer/pull/138
[#143]: https://github.com/stackabletech/druid-opa-authorizer/pull/143

Sorry, fixed it

Copy link
Copy Markdown
Member

@maltesander maltesander left a comment

Choose a reason for hiding this comment

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

Thank you, LGTM :)

@maltesander maltesander added this pull request to the merge queue Apr 2, 2026
Merged via the queue into stackabletech:main with commit 83f2ead Apr 2, 2026
10 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.

OpaAuthorizer creates newHtttpClient on each authorize request causing threads exhaustion under load

2 participants