From 4b02ab9fb0f07a8a0a25befbb5c0875b48f3c11f Mon Sep 17 00:00:00 2001 From: Viktoryia Shabunia Date: Fri, 27 Mar 2026 12:42:29 -0700 Subject: [PATCH 1/4] fix: reuse HttpClient instance across authorize() calls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../tech/stackable/druid/opaauthorizer/OpaAuthorizer.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/tech/stackable/druid/opaauthorizer/OpaAuthorizer.java b/src/main/java/tech/stackable/druid/opaauthorizer/OpaAuthorizer.java index 63d1a2f..551ee15 100644 --- a/src/main/java/tech/stackable/druid/opaauthorizer/OpaAuthorizer.java +++ b/src/main/java/tech/stackable/druid/opaauthorizer/OpaAuthorizer.java @@ -24,10 +24,12 @@ public class OpaAuthorizer implements Authorizer { private static final Logger LOG = new Logger(OpaAuthorizer.class); private final String opaUri; private final ObjectMapper objectMapper; + private final HttpClient httpClient; @JsonCreator public OpaAuthorizer(@JsonProperty("name") String name, @JsonProperty("opaUri") String opaUri) { this.opaUri = opaUri; + this.httpClient = HttpClient.newHttpClient(); objectMapper = new ObjectMapper() // https://github.com/stackabletech/druid-opa-authorizer/issues/72 @@ -53,8 +55,7 @@ public Access authorize( return new Access(false, "Failed to create the OPA request JSON: " + e); } - LOG.trace("Creating HTTP Client and executing post."); - var client = HttpClient.newHttpClient(); + LOG.trace("Executing OPA post."); try { var request = HttpRequest.newBuilder() @@ -63,7 +64,7 @@ public Access authorize( .POST(HttpRequest.BodyPublishers.ofString(msgJson)) .build(); - var response = client.send(request, HttpResponse.BodyHandlers.ofString()); + var response = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); LOG.debug("OPA Response code: %s - %s", response.statusCode(), response.body()); LOG.trace("Parsing OPA response."); From d4775f0be5deb659b90148dd47556665c58832fd Mon Sep 17 00:00:00 2001 From: Viktoryia Shabunia Date: Mon, 30 Mar 2026 10:14:39 -0700 Subject: [PATCH 2/4] updated changelog with new fix --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c2e7f1..f38d7ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,7 @@ [#61]: https://github.com/stackabletech/druid-opa-authorizer/pull/61 [#74]: https://github.com/stackabletech/druid-opa-authorizer/pull/74 [#75]: https://github.com/stackabletech/druid-opa-authorizer/pull/75 +[#143]: https://github.com/stackabletech/druid-opa-authorizer/pull/143 ## [0.3.0] - 2022-10-13 From b810133f08d14b102effa062ce5d49b66dad5edc Mon Sep 17 00:00:00 2001 From: Viktoryia Shabunia Date: Wed, 1 Apr 2026 14:58:48 -0700 Subject: [PATCH 3/4] fixed the changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f38d7ae..8aebf19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ - 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]). @@ -14,6 +18,7 @@ [#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 ## [0.7.0] - 2025-05-31 From ba71507beb7a46e328013de3229847819cdb4a04 Mon Sep 17 00:00:00 2001 From: Viktoryia Shabunia Date: Wed, 1 Apr 2026 15:00:37 -0700 Subject: [PATCH 4/4] fixed changelog --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8aebf19..f33fed5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -67,7 +67,6 @@ [#61]: https://github.com/stackabletech/druid-opa-authorizer/pull/61 [#74]: https://github.com/stackabletech/druid-opa-authorizer/pull/74 [#75]: https://github.com/stackabletech/druid-opa-authorizer/pull/75 -[#143]: https://github.com/stackabletech/druid-opa-authorizer/pull/143 ## [0.3.0] - 2022-10-13