ignore write error for closed connection

This commit is contained in:
Alex Grintsvayg 2019-03-18 16:29:28 -04:00
parent 0d996d7415
commit 7a618f4228
No known key found for this signature in database
GPG key ID: AEB3F089F86A22B5
2 changed files with 8 additions and 19 deletions

View file

@ -7,6 +7,7 @@ import (
"encoding/json" "encoding/json"
"io" "io"
"net" "net"
"strings"
"time" "time"
"github.com/lbryio/reflector.go/reflector" "github.com/lbryio/reflector.go/reflector"
@ -134,20 +135,6 @@ func (s *Server) handleConnection(conn net.Conn) {
log.Error(errors.FullTrace(err)) log.Error(errors.FullTrace(err))
} }
//if strings.Contains(string(request), `"requested_blobs"`) {
// log.Debugln("received availability request")
// response, err = s.handleAvailabilityRequest(request)
//} else if strings.Contains(string(request), `"blob_data_payment_rate"`) {
// log.Debugln("received rate negotiation request")
// response, err = s.handlePaymentRateNegotiation(request)
//} else if strings.Contains(string(request), `"requested_blob"`) {
// log.Debugln("received blob request")
// response, err = s.handleBlobRequest(request)
//} else {
// log.Errorln("invalid request")
// spew.Dump(request)
// return
//}
response, err = s.handleCompositeRequest(request) response, err = s.handleCompositeRequest(request)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
@ -161,7 +148,9 @@ func (s *Server) handleConnection(conn net.Conn) {
n, err := conn.Write(response) n, err := conn.Write(response)
if err != nil { if err != nil {
s.logError(err) if !strings.Contains(err.Error(), "connection reset by peer") { // means the other side closed the connection using TCP reset
s.logError(err)
}
return return
} else if n != len(response) { } else if n != len(response) {
log.Errorln(io.ErrShortWrite) log.Errorln(io.ErrShortWrite)

View file

@ -73,13 +73,13 @@ func (s *Stats) AddError(e error) (shouldLog bool) { // shouldLog is a hack, but
} }
err := errors.Wrap(e, 0) err := errors.Wrap(e, 0)
name := err.TypeName() name := err.TypeName()
if strings.Contains(err.Error(), "i/o timeout") { if strings.Contains(err.Error(), "i/o timeout") { // hit a read or write deadline
name = "i/o timeout" name = "i/o timeout"
} else if strings.Contains(err.Error(), "read: connection reset by peer") { } else if strings.Contains(err.Error(), "read: connection reset by peer") { // the other side closed the connection using TCP reset
name = "read conn reset" name = "read conn reset"
} else if strings.Contains(err.Error(), "unexpected EOF") { } else if strings.Contains(err.Error(), "unexpected EOF") { // tried to read from closed pipe or socket
name = "unexpected EOF" name = "unexpected EOF"
} else if strings.Contains(err.Error(), "write: broken pipe") { } else if strings.Contains(err.Error(), "write: broken pipe") { // tried to write to a pipe or socket that was closed by the peer
name = "write broken pipe" name = "write broken pipe"
} else { } else {
shouldLog = true shouldLog = true