Fix connectionedEndpoint.Readiness() to return EPOLL{RD}HUP appropriately.

Compare net/unix/af_unix.c:unix_poll().

Fixes #7331
Updates dart-lang/sdk#47899
Updates GoogleCloudPlatform/functions-framework-dart#302

PiperOrigin-RevId: 597625614
This commit is contained in:
Ayush Ranjan
2024-01-11 12:34:33 -08:00
committed by gVisor bot
parent d4861911c2
commit 39afbf09cd
4 changed files with 52 additions and 7 deletions
+12 -7
View File
@@ -15,6 +15,7 @@
package transport
import (
"gvisor.dev/gvisor/pkg/atomicbitops"
"gvisor.dev/gvisor/pkg/context"
"gvisor.dev/gvisor/pkg/syserr"
"gvisor.dev/gvisor/pkg/waiter"
@@ -30,7 +31,7 @@ type queue struct {
WriterQueue *waiter.Queue
mu queueMutex `state:"nosave"`
closed bool
closed atomicbitops.Bool
unread bool
used int64
limit int64
@@ -45,10 +46,14 @@ type queue struct {
// q.WriterQueue.Notify(waiter.WritableEvents)
func (q *queue) Close() {
q.mu.Lock()
q.closed = true
q.closed.Store(true)
q.mu.Unlock()
}
func (q *queue) isClosed() bool {
return q.closed.Load()
}
// Reset empties the queue and Releases all of the Entries.
//
// Both the read and write queues must be notified after resetting:
@@ -80,7 +85,7 @@ func (q *queue) IsReadable() bool {
q.mu.Lock()
defer q.mu.Unlock()
return q.closed || q.dataList.Front() != nil
return q.closed.RacyLoad() || q.dataList.Front() != nil
}
// bufWritable returns true if there is space for writing.
@@ -98,7 +103,7 @@ func (q *queue) IsWritable() bool {
q.mu.Lock()
defer q.mu.Unlock()
return q.closed || q.bufWritable()
return q.closed.RacyLoad() || q.bufWritable()
}
// Enqueue adds an entry to the data queue if room is available.
@@ -115,7 +120,7 @@ func (q *queue) IsWritable() bool {
func (q *queue) Enqueue(ctx context.Context, data [][]byte, c ControlMessages, from Address, discardEmpty bool, truncate bool) (l int64, notify bool, err *syserr.Error) {
q.mu.Lock()
if q.closed {
if q.closed.RacyLoad() {
q.mu.Unlock()
return 0, false, syserr.ErrClosedForSend
}
@@ -184,7 +189,7 @@ func (q *queue) Dequeue() (e *message, notify bool, err *syserr.Error) {
if q.dataList.Front() == nil {
err := syserr.ErrWouldBlock
if q.closed {
if q.closed.RacyLoad() {
err = syserr.ErrClosedForReceive
if q.unread {
err = syserr.ErrConnectionReset
@@ -215,7 +220,7 @@ func (q *queue) Peek() (*message, *syserr.Error) {
if q.dataList.Front() == nil {
err := syserr.ErrWouldBlock
if q.closed {
if q.closed.RacyLoad() {
if err = syserr.ErrClosedForReceive; q.unread {
err = syserr.ErrConnectionReset
}