Repository navigation
network: wake blocked internal socket writers when the peer closes - #48409
Conversation
Wake an enabled Write event after detaching a user-space socket peer so connections waiting in CloseAfterFlush can observe the write error and release their pending output. Add regressions for peer destruction after a blocked flush, enabled-event handling, and pending-buffer release. Signed-off-by: Harry Bagdi <[email protected]>
a7b1327 to
03d8f5f
Compare
|
@kyessenov a gentle ping for a review! |
|
/backport This fixes a hang we hit in production with Istio ambient, and we'd like to ask for a backport to Istio's gateways reach backends through an internal listener that runs Standalone reproduction with plain Envoy (one worker): HTTP listener → internal listener with
Istio 1.31 builds on envoy.yaml (run with
|
…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]>
…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]>
…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]>
…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]>
…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]>
…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 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.37): `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 `enable_send_rst_on_user_space_socket`, which this branch does not have. The flag that the peer's close sets is `write_shutdown_` here (renamed `sent_eof_` later). (cherry picked from commit 30a4db3) Signed-off-by: Ryan Northey <[email protected]>
…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 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.37): `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 `enable_send_rst_on_user_space_socket`, which this branch does not have. The flag that the peer's close sets is `write_shutdown_` here (renamed `sent_eof_` later). The tests use `isWritable()`, which `canReceiveData()` was called on this branch. (cherry picked from commit 30a4db3) Signed-off-by: Ryan Northey <[email protected]>
…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 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.37): `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 `enable_send_rst_on_user_space_socket`, which this branch does not have. The flag that the peer's close sets is `write_shutdown_` here (renamed `sent_eof_` later). The tests use `isWritable()`, which `canReceiveData()` was called on this branch. `close()` tells the peer the stream has ended before the peer is told of the destruction here, so the two existing tests that expect one wakeup of the peer on close now expect two. (cherry picked from commit 30a4db3) Signed-off-by: Ryan Northey <[email protected]>
…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]>
…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 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.37): `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 `enable_send_rst_on_user_space_socket`, which this branch does not have. The flag that the peer's close sets is `write_shutdown_` here (renamed `sent_eof_` later). The tests use `isWritable()`, which `canReceiveData()` was called on this branch. `close()` tells the peer the stream has ended before the peer is told of the destruction here, so the two existing tests that expect one wakeup of the peer on close now expect two. (cherry picked from commit 30a4db3) Signed-off-by: Ryan Northey <[email protected]>
…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 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.37): `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 `enable_send_rst_on_user_space_socket`, which this branch does not have. The flag that the peer's close sets is `write_shutdown_` here (renamed `sent_eof_` later). The tests use `isWritable()`, which `canReceiveData()` was called on this branch. `close()` tells the peer the stream has ended before the peer is told of the destruction here, so the two existing tests that expect one wakeup of the peer on close now expect two. (cherry picked from commit 30a4db3) Signed-off-by: Ryan Northey <[email protected]>
Commit Message: network: wake blocked internal socket writers when the peer closes
Additional Description:
An internal connection can enter
CloseAfterFlushwhile 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.