Skip to content

Fix out_forward keepalive reuse after remote close#5309

Open
aviralgarg05 wants to merge 1 commit intofluent:masterfrom
aviralgarg05:fix-forward-keepalive-closed-socket-reuse
Open

Fix out_forward keepalive reuse after remote close#5309
aviralgarg05 wants to merge 1 commit intofluent:masterfrom
aviralgarg05:fix-forward-keepalive-closed-socket-reuse

Conversation

@aviralgarg05
Copy link
Copy Markdown

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

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>
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.

Forward plugin 100% CPU spikes with keepalive enabled

1 participant