Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

otelgrpc: Fix data race in stats handlers when processing messages received and sent metrics #4577

Merged
merged 9 commits into from Nov 16, 2023

Conversation

naphatkrit
Copy link
Contributor

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

```
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
```
Copy link

linux-foundation-easycla bot commented Nov 13, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

Copy link
Contributor

@MrAlias MrAlias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test to highlight the panic you are resolving and prevent regressions.

@naphatkrit
Copy link
Contributor Author

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?

Copy link

codecov bot commented Nov 14, 2023

Codecov Report

Merging #4577 (d590a3b) into main (5ba7d1e) will increase coverage by 0.0%.
Report is 1 commits behind head on main.
The diff coverage is 52.6%.

Additional details and impacted files

Impacted file tree graph

@@          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     
Files Coverage Δ
...n/google.golang.org/grpc/otelgrpc/stats_handler.go 92.5% <100.0%> (+3.7%) ⬆️
...ion/google.golang.org/grpc/otelgrpc/interceptor.go 88.5% <47.0%> (+0.6%) ⬆️

@MrAlias
Copy link
Contributor

MrAlias commented Nov 14, 2023

do you have tests that would catch data races today?

That is my ask. Please add tests to validate this fix.

@naphatkrit
Copy link
Contributor Author

@MrAlias updated

@naphatkrit naphatkrit changed the title fix data race from stats_handler.go (#1) fix data race from stats_handler.go Nov 14, 2023
Co-authored-by: Robert Pająk <pellared@hotmail.com>
@pellared pellared changed the title fix data race from stats_handler.go otelgrpc: Fix data race in stats handlers Nov 15, 2023
@pellared pellared changed the title otelgrpc: Fix data race in stats handlers otelgrpc: Fix data race in stats handlers when processing messages received and sent metrics Nov 15, 2023
@pellared
Copy link
Member

pellared commented Nov 15, 2023

Can you please fix the build (running make should fix the issues) and add the following line to CHANGELOG.md (under Fixed):

- Fix data race in stats handlers when processing messages received and sent metrics in `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc`. (#4577)

@naphatkrit
Copy link
Contributor Author

I wasn't able to run make due to the following failure:

$ make
cd ./tools && \
go build -o /workspaces/opentelemetry-go-contrib/.tools/gotmpl go.opentelemetry.io/build-tools/gotmpl
no required module provides package go.opentelemetry.io/build-tools/gotmpl; to add it:
        go get go.opentelemetry.io/build-tools/gotmpl
make: *** [Makefile:44: /workspaces/opentelemetry-go-contrib/.tools/gotmpl] Error 1

I was able to fix the import manually though.

@pellared
Copy link
Member

I wasn't able to run make due to the following failure:

This is strange. You can try running rm -rf .tools/ before executing make.

The CI is still reporting an issue:

grpc_stats_handler_test.go:37: File is not `goimports`-ed with -local go.opentelemetry.io (goimports)

@naphatkrit
Copy link
Contributor Author

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 make to run

@pellared pellared merged commit d9e86fb into open-telemetry:main Nov 16, 2023
21 of 22 checks passed
@pellared
Copy link
Member

@naphatkrit Thank you very much for your contribution ❤️

@naphatkrit
Copy link
Contributor Author

Thanks for all the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants