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
This commit is contained in:
parent
e395273301
commit
117ac8bc5b
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue