unix: Return ECONNRESET when listener is closed with pending connections#12577
Merged
copybara-service[bot] merged 1 commit intogoogle:masterfrom Feb 6, 2026
Merged
Conversation
f48add9 to
ec041cc
Compare
shailend-g
reviewed
Feb 5, 2026
shailend-g
reviewed
Feb 5, 2026
Contributor
|
Thanks for the patch! |
When a Unix stream socket listener is closed while there are pending (connected but not accepted) connections, gVisor was returning EOF (0) on read() instead of ECONNRESET error, and epoll was not reporting EPOLLERR. This differs from Linux kernel behavior. This change: 1. Sets SO_ERROR to ECONNRESET on client endpoints when listener closes pending connections 2. Notifies waiter queue with EventErr so epoll reports EPOLLERR 3. Makes read() return ECONNRESET on first call, then EOF on subsequent calls (matching Linux's read-once-and-clear semantics) 4. Adds Readiness check for EventErr based on lastError state 5. Adds UpdateLastError to baseEndpoint to support SetLastError This fixes compatibility issues with async frameworks like tokio that rely on these semantics to detect connection failures. Fixes google#12576 Signed-off-by: Tan Yifeng <yiftan@tencent.com>
ec041cc to
20366fd
Compare
copybara-service bot
pushed a commit
that referenced
this pull request
Feb 6, 2026
When a Unix stream socket listener is closed while there are pending (connected but not accepted) connections, gVisor was returning EOF (0) on read() instead of ECONNRESET error, and epoll was not reporting EPOLLERR. This differs from Linux kernel behavior. This change: 1. Sets SO_ERROR to ECONNRESET on client endpoints when listener closes pending connections 2. Notifies waiter queue with EventErr so epoll reports EPOLLERR 3. Makes read() return ECONNRESET on first call, then EOF on subsequent calls (matching Linux's read-once-and-clear semantics) 4. Adds Readiness check for EventErr based on lastError state 5. Adds UpdateLastError to baseEndpoint to support SetLastError This fixes compatibility issues with async frameworks like tokio that rely on these semantics to detect connection failures. Fixes #12576 FUTURE_COPYBARA_INTEGRATE_REVIEW=#12577 from tanyifeng:fix-return-rst 20366fd PiperOrigin-RevId: 866528341
copybara-service bot
pushed a commit
that referenced
this pull request
Feb 6, 2026
When a Unix stream socket listener is closed while there are pending (connected but not accepted) connections, gVisor was returning EOF (0) on read() instead of ECONNRESET error, and epoll was not reporting EPOLLERR. This differs from Linux kernel behavior. This change: 1. Sets SO_ERROR to ECONNRESET on client endpoints when listener closes pending connections 2. Notifies waiter queue with EventErr so epoll reports EPOLLERR 3. Makes read() return ECONNRESET on first call, then EOF on subsequent calls (matching Linux's read-once-and-clear semantics) 4. Adds Readiness check for EventErr based on lastError state 5. Adds UpdateLastError to baseEndpoint to support SetLastError This fixes compatibility issues with async frameworks like tokio that rely on these semantics to detect connection failures. Fixes #12576 FUTURE_COPYBARA_INTEGRATE_REVIEW=#12577 from tanyifeng:fix-return-rst 20366fd PiperOrigin-RevId: 866528341
copybara-service bot
pushed a commit
that referenced
this pull request
Feb 6, 2026
When a Unix stream socket listener is closed while there are pending (connected but not accepted) connections, gVisor was returning EOF (0) on read() instead of ECONNRESET error, and epoll was not reporting EPOLLERR. This differs from Linux kernel behavior. This change: 1. Sets SO_ERROR to ECONNRESET on client endpoints when listener closes pending connections 2. Notifies waiter queue with EventErr so epoll reports EPOLLERR 3. Makes read() return ECONNRESET on first call, then EOF on subsequent calls (matching Linux's read-once-and-clear semantics) 4. Adds Readiness check for EventErr based on lastError state 5. Adds UpdateLastError to baseEndpoint to support SetLastError This fixes compatibility issues with async frameworks like tokio that rely on these semantics to detect connection failures. Fixes #12576 FUTURE_COPYBARA_INTEGRATE_REVIEW=#12577 from tanyifeng:fix-return-rst 20366fd PiperOrigin-RevId: 866528341
copybara-service bot
pushed a commit
that referenced
this pull request
Feb 6, 2026
When a Unix stream socket listener is closed while there are pending (connected but not accepted) connections, gVisor was returning EOF (0) on read() instead of ECONNRESET error, and epoll was not reporting EPOLLERR. This differs from Linux kernel behavior. This change: 1. Sets SO_ERROR to ECONNRESET on client endpoints when listener closes pending connections 2. Notifies waiter queue with EventErr so epoll reports EPOLLERR 3. Makes read() return ECONNRESET on first call, then EOF on subsequent calls (matching Linux's read-once-and-clear semantics) 4. Adds Readiness check for EventErr based on lastError state 5. Adds UpdateLastError to baseEndpoint to support SetLastError This fixes compatibility issues with async frameworks like tokio that rely on these semantics to detect connection failures. Fixes #12576 FUTURE_COPYBARA_INTEGRATE_REVIEW=#12577 from tanyifeng:fix-return-rst 20366fd PiperOrigin-RevId: 866528341
copybara-service bot
pushed a commit
that referenced
this pull request
Feb 6, 2026
When a Unix stream socket listener is closed while there are pending (connected but not accepted) connections, gVisor was returning EOF (0) on read() instead of ECONNRESET error, and epoll was not reporting EPOLLERR. This differs from Linux kernel behavior. This change: 1. Sets SO_ERROR to ECONNRESET on client endpoints when listener closes pending connections 2. Notifies waiter queue with EventErr so epoll reports EPOLLERR 3. Makes read() return ECONNRESET on first call, then EOF on subsequent calls (matching Linux's read-once-and-clear semantics) 4. Adds Readiness check for EventErr based on lastError state 5. Adds UpdateLastError to baseEndpoint to support SetLastError This fixes compatibility issues with async frameworks like tokio that rely on these semantics to detect connection failures. Fixes #12576 FUTURE_COPYBARA_INTEGRATE_REVIEW=#12577 from tanyifeng:fix-return-rst 20366fd PiperOrigin-RevId: 866581924
copybara-service bot
pushed a commit
that referenced
this pull request
Feb 6, 2026
When a Unix stream socket listener is closed while there are pending (connected but not accepted) connections, gVisor was returning EOF (0) on read() instead of ECONNRESET error, and epoll was not reporting EPOLLERR. This differs from Linux kernel behavior. This change: 1. Sets SO_ERROR to ECONNRESET on client endpoints when listener closes pending connections 2. Notifies waiter queue with EventErr so epoll reports EPOLLERR 3. Makes read() return ECONNRESET on first call, then EOF on subsequent calls (matching Linux's read-once-and-clear semantics) 4. Adds Readiness check for EventErr based on lastError state 5. Adds UpdateLastError to baseEndpoint to support SetLastError This fixes compatibility issues with async frameworks like tokio that rely on these semantics to detect connection failures. Fixes #12576 FUTURE_COPYBARA_INTEGRATE_REVIEW=#12577 from tanyifeng:fix-return-rst 20366fd PiperOrigin-RevId: 866581924
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.
When a Unix stream socket listener is closed while there are pending (connected but not accepted) connections, gVisor was returning EOF (0) on read() instead of ECONNRESET error, and epoll was not reporting EPOLLERR. This differs from Linux kernel behavior.
This change:
This fixes compatibility issues with async frameworks like tokio that rely on these semantics to detect connection failures.
Fixes #12576