Skip to content

Backport(v1.19): Fix out_forward keepalive reuse after remote close (#5309) - #5343

Merged
Watson1978 merged 1 commit into
v1.19from
backport-to-v1.19/pr5309
Apr 20, 2026
Merged

Backport(v1.19): Fix out_forward keepalive reuse after remote close (#5309)#5343
Watson1978 merged 1 commit into
v1.19from
backport-to-v1.19/pr5309

Conversation

@github-actions

Copy link
Copy Markdown

Which issue(s) this PR fixes:
Fixes #5269
Fixes #4618

What this PR does / why we need it:
This PR fixes a keepalive socket reuse bug in out_forward.

When a cached keepalive connection has already been closed by the remote side, out_forward could pick that socket back up and try to write to it again. In the reported TLS/NLB setup, that leaves the flush thread spinning on a dead socket and can drive CPU usage to 100%.

The fix is to validate cached sockets before reusing them. If a socket has already become unreadable, closed, or otherwise looks no longer safe to reuse, it is discarded and a new connection is created instead.

This keeps out_forward from reusing half-closed keepalive sockets and avoids the busy-loop behavior described in the issue.

This PR also adds regression coverage to make sure a socket that was closed by the peer is not reused from the keepalive cache.

Docs Changes:
None.

Release Note:

  • out_forward: avoid reusing closed keepalive sockets after remote disconnects

**Which issue(s) this PR fixes**:
Fixes #5269
Fixes #4618

**What this PR does / why we need it**:
This PR fixes a keepalive socket reuse bug in `out_forward`.

When a cached keepalive connection has already been closed by the remote
side, `out_forward` could pick that socket back up and try to write to
it again. In the reported TLS/NLB setup, that leaves the flush thread
spinning on a dead socket and can drive CPU usage to 100%.

The fix is to validate cached sockets before reusing them. If a socket
has already become unreadable, closed, or otherwise looks no longer safe
to reuse, it is discarded and a new connection is created instead.

This keeps `out_forward` from reusing half-closed keepalive sockets and
avoids the busy-loop behavior described in the issue.

This PR also adds regression coverage to make sure a socket that was
closed by the peer is not reused from the keepalive cache.

**Docs Changes**:
None.

**Release Note**:
- out_forward: avoid reusing closed keepalive sockets after remote
disconnects

Signed-off-by: aviralgarg05 <gargaviral99@gmail.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@Watson1978
Watson1978 merged commit 1b849cb into v1.19 Apr 20, 2026
18 checks passed
@Watson1978
Watson1978 deleted the backport-to-v1.19/pr5309 branch April 20, 2026 08:14
@Watson1978 Watson1978 added this to the v1.19.3 milestone Apr 20, 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.

2 participants