From: Brad Fitzpatrick Date: Tue, 26 Jan 2016 20:33:21 +0000 (+0000) Subject: net/http: quiet http2 log spam X-Git-Tag: go1.6rc1~33 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=aff6aa0a21baa332bb94c34795520008c8db9198;p=gostls13.git net/http: quiet http2 log spam Updates x/net/http2 to git rev eb066e3 for https://golang.org/cl/18932 Fixes #13925 Fixes #14061 Change-Id: I73f8c09232877404362358240b7b369bb9c76a12 Reviewed-on: https://go-review.googlesource.com/18934 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- diff --git a/src/net/http/h2_bundle.go b/src/net/http/h2_bundle.go index 2110641955..e7236299e2 100644 --- a/src/net/http/h2_bundle.go +++ b/src/net/http/h2_bundle.go @@ -32,6 +32,7 @@ import ( "net/textproto" "net/url" "os" + "reflect" "runtime" "sort" "strconv" @@ -2850,12 +2851,50 @@ func (sc *http2serverConn) logf(format string, args ...interface{}) { } } +var http2uintptrType = reflect.TypeOf(uintptr(0)) + +// errno returns v's underlying uintptr, else 0. +// +// TODO: remove this helper function once http2 can use build +// tags. See comment in isClosedConnError. +func http2errno(v error) uintptr { + if rv := reflect.ValueOf(v); rv.Kind() == reflect.Uintptr { + return uintptr(rv.Uint()) + } + return 0 +} + +// isClosedConnError reports whether err is an error from use of a closed +// network connection. +func http2isClosedConnError(err error) bool { + if err == nil { + return false + } + + str := err.Error() + if strings.Contains(str, "use of closed network connection") { + return true + } + + if runtime.GOOS == "windows" { + if oe, ok := err.(*net.OpError); ok && oe.Op == "read" { + if se, ok := oe.Err.(*os.SyscallError); ok && se.Syscall == "wsarecv" { + const WSAECONNABORTED = 10053 + const WSAECONNRESET = 10054 + if n := http2errno(se.Err); n == WSAECONNRESET || n == WSAECONNABORTED { + return true + } + } + } + } + return false +} + func (sc *http2serverConn) condlogf(err error, format string, args ...interface{}) { if err == nil { return } - str := err.Error() - if err == io.EOF || strings.Contains(str, "use of closed network connection") { + if err == io.EOF || err == io.ErrUnexpectedEOF || http2isClosedConnError(err) { sc.vlogf(format, args...) } else { @@ -3372,7 +3411,7 @@ func (sc *http2serverConn) processFrameFromReader(res http2readFrameResult) bool sc.goAway(http2ErrCodeFrameSize) return true } - clientGone := err == io.EOF || strings.Contains(err.Error(), "use of closed network connection") + clientGone := err == io.EOF || err == io.ErrUnexpectedEOF || http2isClosedConnError(err) if clientGone { return false @@ -3401,7 +3440,7 @@ func (sc *http2serverConn) processFrameFromReader(res http2readFrameResult) bool return true default: if res.err != nil { - sc.logf("http2: server closing client connection; error reading frame from client %s: %v", sc.conn.RemoteAddr(), err) + sc.vlogf("http2: server closing client connection; error reading frame from client %s: %v", sc.conn.RemoteAddr(), err) } else { sc.logf("http2: server closing client connection: %v", err) }