diff --git a/pkg/protocol/http1/server.go b/pkg/protocol/http1/server.go index c17aa0ff7..a5d33f13d 100644 --- a/pkg/protocol/http1/server.go +++ b/pkg/protocol/http1/server.go @@ -114,7 +114,7 @@ func (s Server) Serve(c context.Context, conn network.Conn) (err error) { defer func() { if s.EnableTrace { - if err != nil && !errors.Is(err, errs.ErrIdleTimeout) && !errors.Is(err, errs.ErrHijacked) { + if shouldRecordInTraceError(err) { ctx.GetTraceInfo().Stats().SetError(err) } // in case of error, we need to trigger all events @@ -460,3 +460,23 @@ func (e *eventStack) pop() func(ti traceinfo.TraceInfo, err error) { *e = (*e)[:len(*e)-1] return last } + +func shouldRecordInTraceError(err error) bool { + if err == nil { + return false + } + + if errors.Is(err, errs.ErrIdleTimeout) { + return false + } + + if errors.Is(err, errs.ErrHijacked) { + return false + } + + if errors.Is(err, errs.ErrShortConnection) { + return false + } + + return true +} diff --git a/pkg/protocol/http1/server_test.go b/pkg/protocol/http1/server_test.go index 5f8f78247..dc8790a97 100644 --- a/pkg/protocol/http1/server_test.go +++ b/pkg/protocol/http1/server_test.go @@ -443,3 +443,13 @@ type mockErrorWriter struct { func (errorWriter *mockErrorWriter) Flush() error { return errors.New("error") } + +func TestShouldRecordInTraceError(t *testing.T) { + assert.False(t, shouldRecordInTraceError(nil)) + assert.False(t, shouldRecordInTraceError(errHijacked)) + assert.False(t, shouldRecordInTraceError(errIdleTimeout)) + assert.False(t, shouldRecordInTraceError(errShortConnection)) + + assert.True(t, shouldRecordInTraceError(errTimeout)) + assert.True(t, shouldRecordInTraceError(errors.New("foo error"))) +} diff --git a/pkg/protocol/uri_windows.go b/pkg/protocol/uri_windows.go index 2e0bf9df8..a40daef98 100644 --- a/pkg/protocol/uri_windows.go +++ b/pkg/protocol/uri_windows.go @@ -67,7 +67,7 @@ func checkSchemeWhenCharIsColon(i int, rawURL []byte) (scheme, path []byte) { // case :\ if i+1 < len(rawURL) && rawURL[i+1] == '\\' { - return nil, rawURL + return nil, rawURL } return rawURL[:i], rawURL[i+1:]