otelgrpc: Fix data race in stats handlers when processing messages received and sent metrics#4577
Conversation
naphatkrit
commented
Nov 13, 2023
```
WARNING: DATA RACE
Read at 0x00c000bef1d8 by goroutine 890:
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc.(*config).handleRPC()
/go/pkg/mod/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc@v0.46.0/stats_handler.go:199 +0x190b
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc.(*clientHandler).HandleRPC()
/go/pkg/mod/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc@v0.46.0/stats_handler.go:124 +0x65
google.golang.org/grpc.(*csAttempt).finish()
/go/pkg/mod/google.golang.org/grpc@v1.59.0/stream.go:1171 +0x650
google.golang.org/grpc.(*clientStream).finish()
/go/pkg/mod/google.golang.org/grpc@v1.59.0/stream.go:988 +0x34b
google.golang.org/grpc.(*clientStream).RecvMsg()
/go/pkg/mod/google.golang.org/grpc@v1.59.0/stream.go:940 +0x2d2
github.com/prodvana/prodvana-public/go/prodvana-sdk/proto/prodvana/agent.(*agentInteractionProxyAPIServerClient).Recv()
/code/go-sdk/proto/prodvana/agent/agent_interaction_grpc.pb.go:181 +0x67
prodvana/grpc/connwrapper.ConnectConnAndStreamingServer[...].func2.2()
grpc/connwrapper/conn.go:141 +0xbc
```
MrAlias
left a comment
There was a problem hiding this comment.
Please add a test to highlight the panic you are resolving and prevent regressions.
|
oh it's not a panic, it's a data race that we caught in our internal integration tests. do you have tests that would catch data races today? |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #4577 +/- ##
=====================================
Coverage 80.8% 80.9%
=====================================
Files 150 150
Lines 10371 10342 -29
=====================================
- Hits 8387 8369 -18
+ Misses 1840 1831 -9
+ Partials 144 142 -2
|
That is my ask. Please add tests to validate this fix. |
|
@MrAlias updated |
Co-authored-by: Robert Pająk <pellared@hotmail.com>
|
Can you please fix the build (running |
|
I wasn't able to run I was able to fix the import manually though. |
This is strange. You can try running The CI is still reporting an issue: |
|
Figured it out - I had an incomplete go.work file I had to add to teach my editor about the various go modules in the repo. Removing it allowed |
|
@naphatkrit Thank you very much for your contribution ❤️ |
|
Thanks for all the help! |