Skip to content

Commit

Permalink
fix open stream metric (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulwe authored Jun 16, 2024
1 parent fbdaf10 commit ac39c85
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/middleware/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"time"

"go.uber.org/atomic"
"google.golang.org/protobuf/proto"

"github.com/livekit/psrpc"
Expand Down Expand Up @@ -115,6 +116,7 @@ type streamMetricsInterceptor struct {
observer MetricsObserver
role MetricRole
info psrpc.RPCInfo
closed atomic.Bool
}

func (s *streamMetricsInterceptor) Recv(msg proto.Message) (err error) {
Expand All @@ -129,7 +131,9 @@ func (s *streamMetricsInterceptor) Send(msg proto.Message, opts ...psrpc.StreamO
}

func (s *streamMetricsInterceptor) Close(cause error) error {
s.observer.OnStreamClose(s.role, s.info)
if !s.closed.Swap(true) {
s.observer.OnStreamClose(s.role, s.info)
}
return s.StreamHandler.Close(cause)
}

Expand Down

0 comments on commit ac39c85

Please sign in to comment.