Skip to content

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

Merged
copybara-service[bot] merged 1 commit intogoogle:masterfrom
tanyifeng:fix-return-rst
Feb 6, 2026
Merged

unix: Return ECONNRESET when listener is closed with pending connections#12577
copybara-service[bot] merged 1 commit intogoogle:masterfrom
tanyifeng:fix-return-rst

Conversation

@tanyifeng
Copy link
Contributor

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

@shailend-g
Copy link
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>
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
@copybara-service copybara-service bot merged commit 3967795 into google:master Feb 6, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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