diff --git a/internal/nodes/http_request.go b/internal/nodes/http_request.go index 98352cf..3ee094b 100644 --- a/internal/nodes/http_request.go +++ b/internal/nodes/http_request.go @@ -1,6 +1,7 @@ package nodes import ( + "context" "errors" "fmt" "github.com/TeaOSLab/EdgeCommon/pkg/configutils" @@ -9,6 +10,7 @@ import ( "github.com/TeaOSLab/EdgeNode/internal/stats" "github.com/TeaOSLab/EdgeNode/internal/utils" "github.com/iwind/TeaGo/types" + "golang.org/x/net/http2" "net" "net/http" "net/url" @@ -1133,3 +1135,24 @@ func (this *HTTPRequest) bytePool(contentLength int64) *utils.BytePool { } return bytePool128k } + +// 检查是否可以忽略错误 +func (this *HTTPRequest) canIgnore(err error) bool { + if err == nil { + return true + } + + // 客户端主动取消 + if err == context.Canceled { + return true + } + + // HTTP/2流错误 + { + _, ok := err.(http2.StreamError) + if ok { + return true + } + } + return false +} diff --git a/internal/nodes/http_request_cache.go b/internal/nodes/http_request_cache.go index e616a15..32af4c9 100644 --- a/internal/nodes/http_request_cache.go +++ b/internal/nodes/http_request_cache.go @@ -6,7 +6,6 @@ import ( "github.com/TeaOSLab/EdgeNode/internal/caches" "github.com/TeaOSLab/EdgeNode/internal/remotelogs" "github.com/iwind/TeaGo/logs" - "golang.org/x/net/http2" "net/http" "strconv" ) @@ -90,7 +89,7 @@ func (this *HTTPRequest) doCacheRead() (shouldStop bool) { return } - if _, ok := err.(http2.StreamError); !ok { + if !this.canIgnore(err) { remotelogs.Error("REQUEST_CACHE", "read from cache failed: "+err.Error()) } return @@ -124,7 +123,7 @@ func (this *HTTPRequest) doCacheRead() (shouldStop bool) { return true, nil }) if err != nil { - if _, ok := err.(http2.StreamError); !ok { + if !this.canIgnore(err) { remotelogs.Error("REQUEST_CACHE", "read from cache failed: "+err.Error()) } return @@ -216,7 +215,7 @@ func (this *HTTPRequest) doCacheRead() (shouldStop bool) { this.writer.WriteHeader(http.StatusRequestedRangeNotSatisfiable) return true } - if _, ok := err.(http2.StreamError); !ok { + if !this.canIgnore(err) { remotelogs.Error("REQUEST_CACHE", "read from cache failed: "+err.Error()) } return @@ -259,7 +258,7 @@ func (this *HTTPRequest) doCacheRead() (shouldStop bool) { return true, err }) if err != nil { - if _, ok := err.(http2.StreamError); !ok { + if !this.canIgnore(err) { remotelogs.Error("REQUEST_CACHE", "read from cache failed: "+err.Error()) } return true @@ -282,7 +281,7 @@ func (this *HTTPRequest) doCacheRead() (shouldStop bool) { return true, nil }) if err != nil { - if _, ok := err.(http2.StreamError); !ok { + if !this.canIgnore(err) { remotelogs.Error("REQUEST_CACHE", "read from cache failed: "+err.Error()) } return diff --git a/internal/nodes/http_request_reverse_proxy.go b/internal/nodes/http_request_reverse_proxy.go index e6658da..7d6ba04 100644 --- a/internal/nodes/http_request_reverse_proxy.go +++ b/internal/nodes/http_request_reverse_proxy.go @@ -7,7 +7,6 @@ import ( "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared" "github.com/TeaOSLab/EdgeNode/internal/remotelogs" "github.com/TeaOSLab/EdgeNode/internal/utils" - "golang.org/x/net/http2" "io" "net/url" "strconv" @@ -257,13 +256,13 @@ func (this *HTTPRequest) doReverseProxy() { err1 := resp.Body.Close() if err1 != nil { - if _, ok := err1.(http2.StreamError); !ok { + if !this.canIgnore(err) { remotelogs.Error("REQUEST_REVERSE_PROXY", err1.Error()) } } if err != nil && err != io.EOF { - if _, ok := err.(http2.StreamError); !ok { + if !this.canIgnore(err) { remotelogs.Error("REQUEST_REVERSE_PROXY", err.Error()) this.addError(err) }