Skip to content

Prune idle per-host connection semaphores#2277

Open
pavel-ptashyts wants to merge 1 commit into
AsyncHttpClient:mainfrom
maygemdev:perf/per-host-semaphore-retention
Open

Prune idle per-host connection semaphores#2277
pavel-ptashyts wants to merge 1 commit into
AsyncHttpClient:mainfrom
maygemdev:perf/per-host-semaphore-retention

Conversation

@pavel-ptashyts

@pavel-ptashyts pavel-ptashyts commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • track active and waiting users of each per-host connection semaphore
  • remove a host entry after its final permit holder or acquisition attempt leaves
  • preserve the same semaphore while another acquisition is waiting, preventing the per-host limit from being bypassed
  • cover standalone and combined connection limiters with retention and concurrency tests

Motivation

PerHostConnectionSemaphore retained one semaphore and partition key for every host observed by a client. Long-lived clients connecting to many distinct hosts could therefore retain these entries indefinitely.

Testing

  • ./mvnw -pl client -Dtest='org.asynchttpclient.netty.channel.SemaphoreTest#perHostRemovesEntriesAfterLastRelease+combinedRemovesEntriesAfterLastRelease+perHostRetainsEntryDuringWaitingAcquire' test
  • ./mvnw -pl client -Dtest='org.asynchttpclient.netty.channel.SemaphoreTest,org.asynchttpclient.netty.channel.ChannelManagerHttp2DrainPermitTest,org.asynchttpclient.netty.NettyRequestThrottleTimeoutTest' test (346 tests)
  • ./mvnw -B -ntp -pl client -DskipTests -Dmaven.javadoc.skip=true -Dgpg.skip=true verify (includes Revapi)

The required JDK 11 ./mvnw clean verify was not run because JDK 11 is not available in the local environment. CI will exercise the complete supported JDK matrix.

Codex on behalf of Pavel Ptashyts

Per-host connection limits retained one semaphore and partition key for every host observed by the client, even after all permits were returned.

Track holders and waiting acquisitions for each map entry. Remove an entry only after the final reference leaves, so a concurrent acquisition cannot detach from the semaphore used by later callers.

Codex on behalf of Pavel Ptashyts

Co-Authored-By: Codex <codex@openai.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.

1 participant