Skip to content

fix #12651: reuse underlying HttpClient in toBlocking() to prevent thread leak [backport 4.10.x]#12653

Open
naborka wants to merge 3 commits into
micronaut-projects:4.10.xfrom
naborka:backport/jdk-toblocking-fix-4.10.x
Open

fix #12651: reuse underlying HttpClient in toBlocking() to prevent thread leak [backport 4.10.x]#12653
naborka wants to merge 3 commits into
micronaut-projects:4.10.xfrom
naborka:backport/jdk-toblocking-fix-4.10.x

Conversation

@naborka
Copy link
Copy Markdown
Contributor

@naborka naborka commented May 3, 2026

Backport of #12652 to 4.10.x.

Fixes #12651

Problem

  • DefaultJdkHttpClient.toBlocking() constructs new JdkBlockingHttpClient + new java.net.http.HttpClient on every call
  • each HttpClient spawns threads and under sync declarative @Client load threads accumulate without bound causing OOMKills

Fix

  • added prototype copy constructor to JdkBlockingHttpClient delegating to AbstractJdkHttpClient(AbstractJdkHttpClient prototype)
  • toBlocking() now calls new JdkBlockingHttpClient(this) and shares existing HttpClient and threads

This mirrors pattern in JdkRawHttpClient

naborka added 3 commits May 3, 2026 16:51
DefaultJdkHttpClient.toBlocking() now constructs JdkBlockingHttpClient via
the existing AbstractJdkHttpClient prototype copy constructor sharing the
underlying java.net.http.HttpClient
@graemerocher
Copy link
Copy Markdown
Contributor

thanks @naborka are all the changes backported here?

@naborka
Copy link
Copy Markdown
Contributor Author

naborka commented May 11, 2026

@graemerocher yes, the same cherrypicked onto the 4.10.x base #12652 commits are present here, both fail spec tests and the fix

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