From 117ac8bc5b4a98cd74c68ac0feed02b5bb4b78b1 Mon Sep 17 00:00:00 2001 From: Ian Gudger Date: Wed, 19 Sep 2018 17:48:24 -0700 Subject: Fix data race on tcp.endpoint.hardError in tcp.(*endpoint).Read tcp.endpoint.hardError is protected by tcp.endpoint.mu. PiperOrigin-RevId: 213730698 Change-Id: I4e4f322ac272b145b500b1a652fbee0c7b985be2 --- pkg/tcpip/transport/tcp/endpoint.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'pkg/tcpip/transport') diff --git a/pkg/tcpip/transport/tcp/endpoint.go b/pkg/tcpip/transport/tcp/endpoint.go index a048cadf8..e82e25233 100644 --- a/pkg/tcpip/transport/tcp/endpoint.go +++ b/pkg/tcpip/transport/tcp/endpoint.go @@ -127,7 +127,7 @@ type endpoint struct { // hardError is meaningful only when state is stateError, it stores the // error to be returned when read/write syscalls are called and the - // endpoint is in this state. + // endpoint is in this state. hardError is protected by mu. hardError *tcpip.Error `state:".(string)"` // workerRunning specifies if a worker goroutine is running. @@ -447,9 +447,10 @@ func (e *endpoint) Read(*tcpip.FullAddress) (buffer.View, tcpip.ControlMessages, bufUsed := e.rcvBufUsed if s := e.state; s != stateConnected && s != stateClosed && bufUsed == 0 { e.rcvListMu.Unlock() + he := e.hardError e.mu.RUnlock() if s == stateError { - return buffer.View{}, tcpip.ControlMessages{}, e.hardError + return buffer.View{}, tcpip.ControlMessages{}, he } return buffer.View{}, tcpip.ControlMessages{}, tcpip.ErrInvalidEndpointState } -- cgit v1.2.3