diff options
author | Jianfeng Tan <henry.tjf@antfin.com> | 2019-08-19 23:13:03 +0800 |
---|---|---|
committer | Jianfeng Tan <henry.tjf@antfin.com> | 2019-08-22 15:25:38 +0000 |
commit | 2c3e2ed2bf4aa61bf317545fe428ff3adac95f92 (patch) | |
tree | 7bbb0df6a63ea89f6fcaed3aea175ca85ad7da04 /pkg/sentry/socket/unix/transport/queue.go | |
parent | 96f78e24668da189f78212e8c23951a461e14a8c (diff) |
unix: return ECONNRESET if peer closed with data not read
For SOCK_STREAM type unix socket, we shall return ECONNRESET if peer is
closed with data not read.
We explictly set a flag when closing one end, to differentiate from
just shutdown (where zero shall be returned).
Fixes: #735
Signed-off-by: Jianfeng Tan <henry.tjf@antfin.com>
Diffstat (limited to 'pkg/sentry/socket/unix/transport/queue.go')
-rw-r--r-- | pkg/sentry/socket/unix/transport/queue.go | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/pkg/sentry/socket/unix/transport/queue.go b/pkg/sentry/socket/unix/transport/queue.go index 0415fae9a..1c71609e2 100644 --- a/pkg/sentry/socket/unix/transport/queue.go +++ b/pkg/sentry/socket/unix/transport/queue.go @@ -33,6 +33,7 @@ type queue struct { mu sync.Mutex `state:"nosave"` closed bool + unread bool used int64 limit int64 dataList messageList @@ -160,7 +161,9 @@ func (q *queue) Dequeue() (e *message, notify bool, err *syserr.Error) { if q.dataList.Front() == nil { err := syserr.ErrWouldBlock if q.closed { - err = syserr.ErrClosedForReceive + if err = syserr.ErrClosedForReceive; q.unread { + err = syserr.ErrConnectionReset + } } q.mu.Unlock() @@ -188,7 +191,9 @@ func (q *queue) Peek() (*message, *syserr.Error) { if q.dataList.Front() == nil { err := syserr.ErrWouldBlock if q.closed { - err = syserr.ErrClosedForReceive + if err = syserr.ErrClosedForReceive; q.unread { + err = syserr.ErrConnectionReset + } } return nil, err } @@ -208,3 +213,11 @@ func (q *queue) QueuedSize() int64 { func (q *queue) MaxQueueSize() int64 { return q.limit } + +// CloseUnread sets flag to indicate that the peer is closed (not shutdown) +// with unread data. So if read on this queue shall return ECONNRESET error. +func (q *queue) CloseUnread() { + q.mu.Lock() + defer q.mu.Unlock() + q.unread = true +} |