Skip to content

fix: reuse MicroProfile mirror-node REST client#85

Open
alejandroGM0 wants to merge 1 commit intohiero-ledger:mainfrom
alejandroGM0:fix/microprofile-mirror-node-resource-leak
Open

fix: reuse MicroProfile mirror-node REST client#85
alejandroGM0 wants to merge 1 commit intohiero-ledger:mainfrom
alejandroGM0:fix/microprofile-mirror-node-resource-leak

Conversation

@alejandroGM0
Copy link
Copy Markdown
Contributor

Summary

  • Reuse a single JAX-RS Client/WebTarget for MicroProfile mirror-node REST calls instead of creating a client per request/page.
  • Close Response resources with try-with-resources and dispose the CDI-managed REST client on shutdown.
  • Treat non-404 4xx/5xx mirror-node responses as errors, including empty-body failures.

Test plan

  • mvn -pl hiero-enterprise-microprofile spotless:check
  • mvn -pl hiero-enterprise-microprofile test -Dtest=MirrorNodeRestClientImplTest -DskipITs
  • mvn -pl hiero-enterprise-microprofile test -Dtest=TokenRepositoryTest#testNullParam+testQueryTokenByIdReturnEmptyOptionalForInvalidId -DskipITs

Closes #78

…rror-node

Every doGetCall and RestBasedPage constructor built a new
jakarta.ws.rs.client.Client without closing it, and only HTTP 404 was
translated; other 4xx/5xx responses were parsed as valid JSON payloads
and surfaced as silent empty results.

- Cache a single Client + WebTarget in MirrorNodeRestClientImpl; make it
  AutoCloseable; close Response objects with try-with-resources.
- Reuse the shared WebTarget in RestBasedPage so pagination no longer
  spawns a client per page.
- Promote MirrorNodeRestClientImpl to an @ApplicationScoped CDI producer
  and release it via @Disposes.
- Non-404 4xx/5xx responses now raise HieroException (or
  IllegalStateException from RestBasedPage, where Page.next() is
  unchecked) with the status code and path.
- Add MirrorNodeRestClientImplTest covering 200/404/4xx/5xx, query-string
  parsing, repeated calls, and close() idempotency using a local
  com.sun.net.httpserver stub.

Closes hiero-ledger#78

Signed-off-by: Alejandro <26930485+alejandroGM0@users.noreply.github.com>
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.

MicroProfile mirror-node leaks a JAX-RS Client per request and swallows non-404 errors

1 participant