summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/transport/unix
diff options
context:
space:
mode:
authorIan Gudger <igudger@google.com>2018-06-26 12:40:23 -0700
committerShentubot <shentubot@google.com>2018-06-26 12:41:22 -0700
commit5f7f78c1d7ee19b6a193d17c48f78edb220412aa (patch)
tree4a03734b643e353488b529c1e732c0a64c5f2dde /pkg/tcpip/transport/unix
parent33041b36cb7e8e9795545837355e4576ff2be4da (diff)
Fix data races in Unix sockets
PiperOrigin-RevId: 202175558 Change-Id: I0113cb9a90d7a0cd7964bf43eef67f70c92d9589
Diffstat (limited to 'pkg/tcpip/transport/unix')
-rw-r--r--pkg/tcpip/transport/unix/unix.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/pkg/tcpip/transport/unix/unix.go b/pkg/tcpip/transport/unix/unix.go
index 72c21a432..34bdb5877 100644
--- a/pkg/tcpip/transport/unix/unix.go
+++ b/pkg/tcpip/transport/unix/unix.go
@@ -384,14 +384,22 @@ func vecCopy(data [][]byte, buf []byte) (uintptr, [][]byte, []byte) {
// Readable implements Receiver.Readable.
func (q *streamQueueReceiver) Readable() bool {
+ q.mu.Lock()
+ bl := len(q.buffer)
+ r := q.readQueue.IsReadable()
+ q.mu.Unlock()
// We're readable if we have data in our buffer or if the queue receiver is
// readable.
- return len(q.buffer) > 0 || q.readQueue.IsReadable()
+ return bl > 0 || r
}
// RecvQueuedSize implements Receiver.RecvQueuedSize.
func (q *streamQueueReceiver) RecvQueuedSize() int64 {
- return int64(len(q.buffer)) + q.readQueue.QueuedSize()
+ q.mu.Lock()
+ bl := len(q.buffer)
+ qs := q.readQueue.QueuedSize()
+ q.mu.Unlock()
+ return int64(bl) + qs
}
// RecvMaxQueueSize implements Receiver.RecvMaxQueueSize.