[receiver/statsd] fix data race in TCP server shutdown#42986
Closed
asweet-confluent wants to merge 1 commit into
Closed
[receiver/statsd] fix data race in TCP server shutdown#42986asweet-confluent wants to merge 1 commit into
asweet-confluent wants to merge 1 commit into
Conversation
8696c3d to
2d1ca79
Compare
2d1ca79 to
a0cd3e5
Compare
Contributor
|
Please take a look at the conflict and mark ready to review again |
Contributor
Author
|
Looks like @axw beat me to this one. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes a data race that occurs when shutdown is called while a new connection is created.
ListenAndServeruns in a goroutine created here, and apparently WaitGroups aren't safe to use in this way.The UDP and UDS implementations don't use a WaitGroup and are unaffected.
Race detector log
================== WARNING: DATA RACE Write at 0x00c0000f8c08 by goroutine 15: runtime.racewrite() <autogenerated>:1 +0x1e github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver/internal/transport.(*tcpServer).Close() /home/semaphore/opentelemetry-collector-contrib/receiver/statsdreceiver/internal/transport/tcp_server.go:114 +0x48 github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver/internal/transport.Test_Server_ListenAndServe.func1() /home/semaphore/opentelemetry-collector-contrib/receiver/statsdreceiver/internal/transport/server_test.go:112 +0xb64 testing.tRunner() /home/semaphore/.local/share/mise/installs/go/1.23.11/packages/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.0.linux-amd64/src/testing/testing.go:1792 +0x225 testing.(*T).Run.gowrap1() /home/semaphore/.local/share/mise/installs/go/1.23.11/packages/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.0.linux-amd64/src/testing/testing.go:1851 +0x44 Previous read at 0x00c0000f8c08 by goroutine 17: runtime.raceread() <autogenerated>:1 +0x1e github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver/internal/transport.(*tcpServer).ListenAndServe() /home/semaphore/opentelemetry-collector-contrib/receiver/statsdreceiver/internal/transport/tcp_server.go:72 +0x2ae github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver/internal/transport.Test_Server_ListenAndServe.func1.1() /home/semaphore/opentelemetry-collector-contrib/receiver/statsdreceiver/internal/transport/server_test.go:84 +0x105 Goroutine 15 (running) created at: testing.(*T).Run() /home/semaphore/.local/share/mise/installs/go/1.23.11/packages/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.0.linux-amd64/src/testing/testing.go:1851 +0x8f2 github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver/internal/transport.Test_Server_ListenAndServe() /home/semaphore/opentelemetry-collector-contrib/receiver/statsdreceiver/internal/transport/server_test.go:58 +0x28b testing.tRunner() /home/semaphore/.local/share/mise/installs/go/1.23.11/packages/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.0.linux-amd64/src/testing/testing.go:1792 +0x225 testing.(*T).Run.gowrap1() /home/semaphore/.local/share/mise/installs/go/1.23.11/packages/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.0.linux-amd64/src/testing/testing.go:1851 +0x44 Goroutine 17 (running) created at: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver/internal/transport.Test_Server_ListenAndServe.func1() /home/semaphore/opentelemetry-collector-contrib/receiver/statsdreceiver/internal/transport/server_test.go:82 +0x7bc testing.tRunner() /home/semaphore/.local/share/mise/installs/go/1.23.11/packages/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.0.linux-amd64/src/testing/testing.go:1792 +0x225 testing.(*T).Run.gowrap1() /home/semaphore/.local/share/mise/installs/go/1.23.11/packages/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.0.linux-amd64/src/testing/testing.go:1851 +0x44 ================== testing.go:1490: race detected during execution of test === �[31mFAIL�[0m: internal/transport Test_Server_ListenAndServe (1.01s)