Skip to content

Conversation

asweet-confluent
Copy link
Contributor

Description

Fixes a data race that occurs when shutdown is called while a new connection is created. ListenAndServe runs 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)

@asweet-confluent asweet-confluent requested review from dmitryax and a team as code owners September 25, 2025 19:09
@github-actions github-actions bot added the receiver/statsd statsd related issues label Sep 25, 2025
@github-actions github-actions bot requested a review from jmacd September 25, 2025 19:10
@asweet-confluent asweet-confluent force-pushed the fix-statsd-tcp-server-data-race branch from 8696c3d to 2d1ca79 Compare September 25, 2025 19:10
@asweet-confluent asweet-confluent force-pushed the fix-statsd-tcp-server-data-race branch from 2d1ca79 to a0cd3e5 Compare September 25, 2025 19:13
@atoulme
Copy link
Contributor

atoulme commented Sep 27, 2025

Please take a look at the conflict and mark ready to review again

@atoulme atoulme marked this pull request as draft September 27, 2025 00:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
receiver/statsd statsd related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants