Skip to content

unix: Return ECONNRESET when listener is closed with pending connections#12594

Merged
copybara-service[bot] merged 2 commits intomasterfrom
test/cl866581924
Feb 6, 2026
Merged

unix: Return ECONNRESET when listener is closed with pending connections#12594
copybara-service[bot] merged 2 commits intomasterfrom
test/cl866581924

Conversation

@copybara-service
Copy link

unix: Return ECONNRESET when listener is closed with pending connections

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

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

Signed-off-by: Tan Yifeng <yiftan@tencent.com>
@copybara-service copybara-service bot added the exported Issue was exported automatically label Feb 6, 2026
@copybara-service copybara-service bot merged commit 3967795 into master Feb 6, 2026
0 of 2 checks passed
@copybara-service copybara-service bot deleted the test/cl866581924 branch February 6, 2026 23:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

exported Issue was exported automatically

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Unix Socket pending connections receive EOF instead of ECONNRESET when listener closes

2 participants