Skip to content

fix: close leaked HTTP client in getHttpClientResponse()#792

Open
ayuxsh009 wants to merge 1 commit into
mosip:masterfrom
ayuxsh009:fix/http-client-leak
Open

fix: close leaked HTTP client in getHttpClientResponse()#792
ayuxsh009 wants to merge 1 commit into
mosip:masterfrom
ayuxsh009:fix/http-client-leak

Conversation

@ayuxsh009
Copy link
Copy Markdown

Summary

Fixes an HTTP resource leak in MosipDeviceSpecificationHelper#getHttpClientResponse()
where a new CloseableHttpClient was created for every MDM request but never closed.

This affected stream, rcapture, and device info operations for spec 0.9.5
devices and could progressively exhaust JVM socket/file descriptors during
normal registration sessions.

Fixes #791


Root Cause

getHttpClientResponse() returned a raw CloseableHttpResponse while the
internally created CloseableHttpClient remained unmanaged.

CloseableHttpClient client = HttpClients.createDefault();
return client.execute(httpUriRequest);

Because the client lifecycle was detached from the caller, sockets and HTTP
connections accumulated over repeated biometric operations.


Fix

Changed the method return type from CloseableHttpResponse to InputStream.

The method now:

  • wraps response content in a FilterInputStream
  • closes both CloseableHttpResponse and CloseableHttpClient
    when the stream is closed
  • safely closes the client on IOException before rethrowing

Updated the only caller in
MosipDeviceSpecification_095_ProviderImpl to consume InputStream
directly and removed the unused CloseableHttpResponse import.


Files Changed

  • MosipDeviceSpecificationHelper.java

    • fixed HTTP client/resource leak
    • changed return type to InputStream
  • MosipDeviceSpecification_095_ProviderImpl.java

    • updated caller implementation
  • BioServiceTest.java

    • added stream lifecycle test
    • added 204 No Content handling test

Signed-off-by: ayuxsh009 <1raj.aayush@gmail.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

Warning

Rate limit exceeded

@ayuxsh009 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 36 minutes and 49 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: e49c420b-f48c-4501-beb0-7531a334048d

📥 Commits

Reviewing files that changed from the base of the PR and between 22fe01f and e74f05d.

📒 Files selected for processing (3)
  • registration/registration-services/src/main/java/io/mosip/registration/mdm/service/impl/MosipDeviceSpecificationHelper.java
  • registration/registration-services/src/main/java/io/mosip/registration/mdm/spec_0_9_5/service/impl/MosipDeviceSpecification_095_ProviderImpl.java
  • registration/registration-services/src/test/java/io/mosip/registration/bio/service/test/BioServiceTest.java

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ayuxsh009 ayuxsh009 changed the title fix: close leaked HTTP client in getHttpClientResponse() fix: close leaked HTTP client in getHttpClientResponse() May 14, 2026
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.

[BUG] CloseableHttpClient never closed in MosipDeviceSpecificationHelper.getHttpClientResponse()

1 participant