Skip to content

Refactor in-flight requests tracking (Continues #7281 / Fixes #7277)#1

Closed
pauloappbr wants to merge 1 commit intou5surf:issue-7277from
pauloappbr:issue-7277
Closed

Refactor in-flight requests tracking (Continues #7281 / Fixes #7277)#1
pauloappbr wants to merge 1 commit intou5surf:issue-7277from
pauloappbr:issue-7277

Conversation

@pauloappbr
Copy link

Assistance Disclosure

I consulted an AI assistant (Gemini) to help refactor the UsagePool logic into the sync.RWMutex map approach suggested by @mholt, and to ensure the Git co-authoring flow was handled correctly. I fully reviewed, authored the final structure, and verified the code's correctness.


Hey @u5surf and @mholt!

I saw PR caddyserver#7281 was stalled for a bit, but the feature requested in caddyserver#7277 is incredibly useful for connection draining observability.

I took the liberty to implement the approach suggested by @mholt in the review comments. Instead of hacking UsagePool, this implementation uses a lightweight, package-level map[string]uint protected by a sync.RWMutex.

Changes:

  • Removed inflightHosts UsagePool logic.
  • Implemented inFlightRequests map to track requests during the proxy loop securely.
  • Updated admin.go to expose these draining hosts alongside the static hosts in /reverse_proxy/upstreams.
  • Fixed the double-counting issue pointed out by @huang041.
  • Zero memory leak: hosts are deleted from the map as soon as their in-flight count reaches 0.

@u5surf, I've added you as a co-author since this builds directly upon your initial work and test cases. If you merge this into your branch, it will automatically update your main PR on the Caddy repo!

…server#7277)

This refactors the initial approach in PR caddyserver#7281, replacing the UsagePool
with a dedicated package-level map protected by a sync.RWMutex. This
addresses maintainer feedback, avoids double-counting bugs, and ensures
that draining upstreams are correctly exposed via the admin API across
config reloads without leaking memory.

Co-authored-by: Y.Horie <u5.horie@gmail.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