Skip to content

Commit

Permalink
fix: stream event handler ignore io.EOF event
Browse files Browse the repository at this point in the history
  • Loading branch information
joway committed Oct 14, 2024
1 parent 257f23b commit eae8b91
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
8 changes: 7 additions & 1 deletion pkg/rpcinfo/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package rpcinfo

import (
"context"
"errors"
"io"
"runtime/debug"

Expand Down Expand Up @@ -75,7 +76,7 @@ func (c *TraceController) DoFinish(ctx context.Context, ri RPCInfo, err error) {
}

func buildStreamingEvent(statsEvent stats.Event, err error) Event {
if err == nil || err == io.EOF {
if err == nil {
return NewEvent(statsEvent, stats.StatusInfo, "")
} else {
return NewEvent(statsEvent, stats.StatusError, err.Error())
Expand All @@ -87,6 +88,11 @@ func (c *TraceController) ReportStreamEvent(ctx context.Context, statsEvent stat
if !c.HasStreamEventReporter() {
return
}
// we should ignore event if stream.RecvMsg return EOF
// because it means there is no data incoming and stream closed by peer normally
if errors.Is(err, io.EOF) {
return
}
defer c.tryRecover(ctx)
event := buildStreamingEvent(statsEvent, err)
defer func() {
Expand Down
7 changes: 0 additions & 7 deletions pkg/rpcinfo/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,6 @@ func Test_buildStreamingEvent(t *testing.T) {
test.Assert(t, evt.Info() == "")
})

t.Run("io.EOF", func(t *testing.T) {
evt := buildStreamingEvent(stats.StreamSend, io.EOF)
test.Assert(t, evt.Event() == stats.StreamSend)
test.Assert(t, evt.Status() == stats.StatusInfo)
test.Assert(t, evt.Info() == "")
})

t.Run("error", func(t *testing.T) {
err := errors.New("XXX")
evt := buildStreamingEvent(stats.StreamSend, err)
Expand Down

0 comments on commit eae8b91

Please sign in to comment.