Skip to content

Commit

Permalink
optimize: remove short connection error in trace (#1010)
Browse files Browse the repository at this point in the history
  • Loading branch information
welkeyever authored Dec 1, 2023
1 parent a327795 commit 85d1aff
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
22 changes: 21 additions & 1 deletion pkg/protocol/http1/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
10 changes: 10 additions & 0 deletions pkg/protocol/http1/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
}
2 changes: 1 addition & 1 deletion pkg/protocol/uri_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:]
Expand Down

0 comments on commit 85d1aff

Please sign in to comment.