Skip to content
This repository has been archived by the owner on May 20, 2020. It is now read-only.

Commit

Permalink
Read should return buffered data before errors.
Browse files Browse the repository at this point in the history
Netstack should fully drain receive buffer on calls to read
when in an error state (such as RST received) before returning
an ECONNRESET.

PiperOrigin-RevId: 193734391
  • Loading branch information
bgaff authored and shentubot committed Apr 20, 2018
1 parent c9e01b6 commit c6f7dce
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions tcpip/transport/tcp/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,11 @@ func (e *endpoint) cleanup() {
// Read reads data from the endpoint.
func (e *endpoint) Read(*tcpip.FullAddress) (buffer.View, *tcpip.Error) {
e.mu.RLock()

// The endpoint can be read if it's connected, or if it's already closed
// but has some pending unread data.
if s := e.state; s != stateConnected && s != stateClosed {
// but has some pending unread data. Also note that a RST being received
// would cause the state to become stateError so we should allow the
// reads to proceed before returning a ECONNRESET.
if s := e.state; s != stateConnected && s != stateClosed && e.rcvBufUsed == 0 {
e.mu.RUnlock()
if s == stateError {
return buffer.View{}, e.hardError
Expand Down

0 comments on commit c6f7dce

Please sign in to comment.