Repository navigation
userspace socket: treat a closed peer handle as writable - #43976
Merged
Merged
Conversation
Signed-off-by: Eugene Chan <[email protected]>
… descheduled. Signed-off-by: Eugene Chan <[email protected]>
Signed-off-by: Eugene Chan <[email protected]>
Signed-off-by: Eugene Chan <[email protected]>
Signed-off-by: Eugene Chan <[email protected]>
Signed-off-by: Eugene Chan <[email protected]>
Signed-off-by: Eugene Chan <[email protected]>
Signed-off-by: Eugene Chan <[email protected]>
…ndle-write Signed-off-by: Eugene Chan <[email protected]>
pianiststickman
marked this pull request as ready for review
March 19, 2026 01:38
Contributor
|
/assign @botengyao |
Member
|
gently ping @botengyao |
botengyao
reviewed
Mar 26, 2026
botengyao
left a comment
Member
There was a problem hiding this comment.
Thanks for addressing this! could you also add a bug fix changelog for this?
/wait
Signed-off-by: Eugene Chan <[email protected]>
Signed-off-by: pianiststickman <[email protected]>
Signed-off-by: Eugene Chan <[email protected]>
…to io-handle-write
Member
|
/retest |
TAOXUY
pushed a commit
to TAOXUY/envoy
that referenced
this pull request
Apr 1, 2026
…43976) Commit Message: userspace socket: treat a closed peer handle as writable Additional Description: If one side of an internal listener connection closes, subsequent writes from the other side may result in data waiting to be flushed on a half-close. For connections managed by the HCM, this is covered by the delayed close timer, but TcpProxy does not implement a delayed close timer and therefore the connection leak in envoyproxy#38148 can persist. The fix here is treat a closed peer handle as writable in order to get the connection to attempt a write and error out. (This is analogous to Linux signalling `EPOLLOUT` along with `EPOLLHUP` when a peer closes for reads; without it, an epoll consumer on the other side may continue to write-block a socket indefinitely, which is exactly what's happening here but in userspace.) Risk Level: low; subsequent calls to `write()` are guarded against peer being nullptr, and the error when calling `write()` is the point. Testing: new CI and integration test that reproduces the issue Docs Changes: n/a Release Notes: n/a Fixes envoyproxy#38148 --------- Signed-off-by: Eugene Chan <[email protected]> Signed-off-by: pianiststickman <[email protected]> Signed-off-by: Xuyang Tao <[email protected]>
citrus7
pushed a commit
to citrus7/envoy
that referenced
this pull request
Apr 1, 2026
…43976) Commit Message: userspace socket: treat a closed peer handle as writable Additional Description: If one side of an internal listener connection closes, subsequent writes from the other side may result in data waiting to be flushed on a half-close. For connections managed by the HCM, this is covered by the delayed close timer, but TcpProxy does not implement a delayed close timer and therefore the connection leak in envoyproxy#38148 can persist. The fix here is treat a closed peer handle as writable in order to get the connection to attempt a write and error out. (This is analogous to Linux signalling `EPOLLOUT` along with `EPOLLHUP` when a peer closes for reads; without it, an epoll consumer on the other side may continue to write-block a socket indefinitely, which is exactly what's happening here but in userspace.) Risk Level: low; subsequent calls to `write()` are guarded against peer being nullptr, and the error when calling `write()` is the point. Testing: new CI and integration test that reproduces the issue Docs Changes: n/a Release Notes: n/a Fixes envoyproxy#38148 --------- Signed-off-by: Eugene Chan <[email protected]> Signed-off-by: pianiststickman <[email protected]> Signed-off-by: Jonathan Wu <[email protected]>
nshipilov
pushed a commit
to nshipilov/envoy
that referenced
this pull request
Apr 13, 2026
…43976) Commit Message: userspace socket: treat a closed peer handle as writable Additional Description: If one side of an internal listener connection closes, subsequent writes from the other side may result in data waiting to be flushed on a half-close. For connections managed by the HCM, this is covered by the delayed close timer, but TcpProxy does not implement a delayed close timer and therefore the connection leak in envoyproxy#38148 can persist. The fix here is treat a closed peer handle as writable in order to get the connection to attempt a write and error out. (This is analogous to Linux signalling `EPOLLOUT` along with `EPOLLHUP` when a peer closes for reads; without it, an epoll consumer on the other side may continue to write-block a socket indefinitely, which is exactly what's happening here but in userspace.) Risk Level: low; subsequent calls to `write()` are guarded against peer being nullptr, and the error when calling `write()` is the point. Testing: new CI and integration test that reproduces the issue Docs Changes: n/a Release Notes: n/a Fixes envoyproxy#38148 --------- Signed-off-by: Eugene Chan <[email protected]> Signed-off-by: pianiststickman <[email protected]> Signed-off-by: Nick Shipilov <[email protected]>
krinkinmu
pushed a commit
to grnmeira/envoy
that referenced
this pull request
Apr 20, 2026
…43976) Commit Message: userspace socket: treat a closed peer handle as writable Additional Description: If one side of an internal listener connection closes, subsequent writes from the other side may result in data waiting to be flushed on a half-close. For connections managed by the HCM, this is covered by the delayed close timer, but TcpProxy does not implement a delayed close timer and therefore the connection leak in envoyproxy#38148 can persist. The fix here is treat a closed peer handle as writable in order to get the connection to attempt a write and error out. (This is analogous to Linux signalling `EPOLLOUT` along with `EPOLLHUP` when a peer closes for reads; without it, an epoll consumer on the other side may continue to write-block a socket indefinitely, which is exactly what's happening here but in userspace.) Risk Level: low; subsequent calls to `write()` are guarded against peer being nullptr, and the error when calling `write()` is the point. Testing: new CI and integration test that reproduces the issue Docs Changes: n/a Release Notes: n/a Fixes envoyproxy#38148 --------- Signed-off-by: Eugene Chan <[email protected]> Signed-off-by: pianiststickman <[email protected]>
yanavlasov
pushed a commit
that referenced
this pull request
Oct 21, 2026
…48409) An internal connection can enter `CloseAfterFlush` while its peer's receive buffer is full, leaving only Write enabled and no callback scheduled. If the peer then closes, the EOF notification cannot wake that writer, so the connection can remain stuck retaining its pending output. Activate an enabled Write event after clearing the peer state. The pending flush then observes the write error and closes. This complements #43976, which makes a closed peer write-unblocked when readiness is checked but does not schedule a callback for a writer that was already blocked. Risk Level: Medium Runtime Guard: N/A Docs Changes: N/A Release Notes: Added a bug-fix fragment describing retained-buffer cleanup. AI assistance: Codex assisted with investigation, implementation, tests, and review. Signed-off-by: Harry Bagdi <[email protected]>
phlax
pushed a commit
to phlax/envoy
that referenced
this pull request
Nov 17, 2026
…nvoyproxy#48409) An internal connection can enter `CloseAfterFlush` while its peer's receive buffer is full, leaving only Write enabled and no callback scheduled. If the peer then closes, the EOF notification cannot wake that writer, so the connection can remain stuck retaining its pending output. Activate an enabled Write event after clearing the peer state. The pending flush then observes the write error and closes. This complements envoyproxy#43976, which makes a closed peer write-unblocked when readiness is checked but does not schedule a callback for a writer that was already blocked. Risk Level: Medium Runtime Guard: N/A Docs Changes: N/A Release Notes: Added a bug-fix fragment describing retained-buffer cleanup. AI assistance: Codex assisted with investigation, implementation, tests, and review. Signed-off-by: Harry Bagdi <[email protected]> (cherry picked from commit 30a4db3) Signed-off-by: Ryan Northey <[email protected]>
phlax
pushed a commit
to phlax/envoy
that referenced
this pull request
Nov 17, 2026
…nvoyproxy#48409) An internal connection can enter `CloseAfterFlush` while its peer's receive buffer is full, leaving only Write enabled and no callback scheduled. If the peer then closes, the EOF notification cannot wake that writer, so the connection can remain stuck retaining its pending output. Activate an enabled Write event after clearing the peer state. The pending flush then observes the write error and closes. This complements envoyproxy#43976, which makes a closed peer write-unblocked when readiness is checked but does not schedule a callback for a writer that was already blocked. Risk Level: Medium Runtime Guard: N/A Docs Changes: N/A Release Notes: Added a bug-fix fragment describing retained-buffer cleanup. AI assistance: Codex assisted with investigation, implementation, tests, and review. Signed-off-by: Harry Bagdi <[email protected]> Backport note (release/v1.39): `onPeerDestroy()` is inline in `io_handle_impl.h` on this branch, so the wakeup goes there. The connection test goes in `connection_compatbility_test.cc` (renamed by envoyproxy#47867, not on this branch) and is not parameterized on `enable_send_rst_on_user_space_socket`, which this branch does not have. (cherry picked from commit 30a4db3) Signed-off-by: Ryan Northey <[email protected]>
phlax
pushed a commit
that referenced
this pull request
Nov 17, 2026
…48409) An internal connection can enter `CloseAfterFlush` while its peer's receive buffer is full, leaving only Write enabled and no callback scheduled. If the peer then closes, the EOF notification cannot wake that writer, so the connection can remain stuck retaining its pending output. Activate an enabled Write event after clearing the peer state. The pending flush then observes the write error and closes. This complements #43976, which makes a closed peer write-unblocked when readiness is checked but does not schedule a callback for a writer that was already blocked. Risk Level: Medium Runtime Guard: N/A Docs Changes: N/A Release Notes: Added a bug-fix fragment describing retained-buffer cleanup. AI assistance: Codex assisted with investigation, implementation, tests, and review. Signed-off-by: Harry Bagdi <[email protected]> (cherry picked from commit 30a4db3) Signed-off-by: Ryan Northey <[email protected]>
phlax
pushed a commit
to phlax/envoy
that referenced
this pull request
Nov 17, 2026
…nvoyproxy#48409) An internal connection can enter `CloseAfterFlush` while its peer's receive buffer is full, leaving only Write enabled and no callback scheduled. If the peer then closes, the EOF notification cannot wake that writer, so the connection can remain stuck retaining its pending output. Activate an enabled Write event after clearing the peer state. The pending flush then observes the write error and closes. This complements envoyproxy#43976, which makes a closed peer write-unblocked when readiness is checked but does not schedule a callback for a writer that was already blocked. Risk Level: Medium Runtime Guard: N/A Docs Changes: N/A Release Notes: Added a bug-fix fragment describing retained-buffer cleanup. AI assistance: Codex assisted with investigation, implementation, tests, and review. Signed-off-by: Harry Bagdi <[email protected]> Backport note (release/v1.39): `onPeerDestroy()` is inline in `io_handle_impl.h` on this branch, so the wakeup goes there. The connection test goes in `connection_compatbility_test.cc` (renamed by envoyproxy#47867, not on this branch) and is not parameterized on `enable_send_rst_on_user_space_socket`, which this branch does not have. (cherry picked from commit 30a4db3) Signed-off-by: Ryan Northey <[email protected]>
phlax
pushed a commit
to phlax/envoy
that referenced
this pull request
Nov 17, 2026
…nvoyproxy#48409) An internal connection can enter `CloseAfterFlush` while its peer's receive buffer is full, leaving only Write enabled and no callback scheduled. If the peer then closes, the EOF notification cannot wake that writer, so the connection can remain stuck retaining its pending output. Activate an enabled Write event after clearing the peer state. The pending flush then observes the write error and closes. This complements envoyproxy#43976, which makes a closed peer write-unblocked when readiness is checked but does not schedule a callback for a writer that was already blocked. Risk Level: Medium Runtime Guard: N/A Docs Changes: N/A Release Notes: Added a bug-fix fragment describing retained-buffer cleanup. AI assistance: Codex assisted with investigation, implementation, tests, and review. Signed-off-by: Harry Bagdi <[email protected]> Backport note (release/v1.38): `onPeerDestroy()` is inline in `io_handle_impl.h` on this branch, so the wakeup goes there. The connection test goes in `connection_compatbility_test.cc` (renamed by envoyproxy#47867, not on this branch) and is not parameterized on `enable_send_rst_on_user_space_socket`, which this branch does not have. (cherry picked from commit 30a4db3) Signed-off-by: Ryan Northey <[email protected]>
phlax
pushed a commit
that referenced
this pull request
Nov 17, 2026
…48409) An internal connection can enter `CloseAfterFlush` while its peer's receive buffer is full, leaving only Write enabled and no callback scheduled. If the peer then closes, the EOF notification cannot wake that writer, so the connection can remain stuck retaining its pending output. Activate an enabled Write event after clearing the peer state. The pending flush then observes the write error and closes. This complements #43976, which makes a closed peer write-unblocked when readiness is checked but does not schedule a callback for a writer that was already blocked. Risk Level: Medium Runtime Guard: N/A Docs Changes: N/A Release Notes: Added a bug-fix fragment describing retained-buffer cleanup. AI assistance: Codex assisted with investigation, implementation, tests, and review. Signed-off-by: Harry Bagdi <[email protected]> Backport note (release/v1.38): `onPeerDestroy()` is inline in `io_handle_impl.h` on this branch, so the wakeup goes there. The connection test goes in `connection_compatbility_test.cc` (renamed by #47867, not on this branch) and is not parameterized on `enable_send_rst_on_user_space_socket`, which this branch does not have. (cherry picked from commit 30a4db3) Signed-off-by: Ryan Northey <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Commit Message: userspace socket: treat a closed peer handle as writable
Additional Description:
If one side of an internal listener connection closes, subsequent writes from the other side may result in data waiting to be flushed on a half-close. For connections managed by the HCM, this is covered by the delayed close timer, but TcpProxy does not implement a delayed close timer and therefore the connection leak in #38148 can persist.
The fix here is treat a closed peer handle as writable in order to get the connection to attempt a write and error out. (This is analogous to Linux signalling
EPOLLOUTalong withEPOLLHUPwhen a peer closes for reads; without it, an epoll consumer on the other side may continue to write-block a socket indefinitely, which is exactly what's happening here but in userspace.)Risk Level: low; subsequent calls to
write()are guarded against peer being nullptr, and the error when callingwrite()is the point.Testing: new CI and integration test that reproduces the issue
Docs Changes: n/a
Release Notes: n/a
Fixes #38148