[receiver/statsd] Clean up stale unix socket on startup#47724
Open
Vanshul97 wants to merge 1 commit intoopen-telemetry:mainfrom
Open
[receiver/statsd] Clean up stale unix socket on startup#47724Vanshul97 wants to merge 1 commit intoopen-telemetry:mainfrom
Vanshul97 wants to merge 1 commit intoopen-telemetry:mainfrom
Conversation
Contributor
|
Welcome, contributor! Thank you for your contribution to opentelemetry-collector-contrib. Important reminders:
A maintainer will review your pull request soon. Thank you for helping make OpenTelemetry better! |
Remove any existing socket file before calling net.ListenPacket to prevent "address already in use" errors when the receiver restarts after an unclean shutdown (crash, SIGKILL). This is standard practice for unix socket servers. Fixes open-telemetry#44866
d56ab71 to
7eea7dd
Compare
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.
Summary
Clean up stale unix socket files on startup to prevent "address already in use" errors when the StatsD receiver restarts after an unclean shutdown.
Fixes #44866
Problem
When the StatsD receiver is configured with UDS (unix domain socket) transport and the collector process is killed ungracefully (SIGKILL, OOM, crash), the socket file is not cleaned up. On restart,
net.ListenPacketfails because the stale socket file still exists:The
Close()method does remove the socket file, but it never runs during an unclean shutdown.Fix
Added
os.Remove(socketPath)beforenet.ListenPacket()inNewUDSServer(). This removes any stale socket file from a previous instance. The error is intentionally ignored since the file won't exist on first startup.This is the standard pattern for unix socket servers, used throughout the Go ecosystem and within this repo (e.g.,
internal/docker/docker_test_listener.go,receiver/podmanreceiver).Test Plan
Test_NewUDSServer_CleansUpStaleSocketthat simulates a crash (closes connection without removing socket file) and verifies a new server can start on the same path