Skip to content

[receiver/statsd] Clean up stale unix socket on startup#47724

Open
Vanshul97 wants to merge 1 commit intoopen-telemetry:mainfrom
Vanshul97:fix/statsd-uds-socket-cleanup
Open

[receiver/statsd] Clean up stale unix socket on startup#47724
Vanshul97 wants to merge 1 commit intoopen-telemetry:mainfrom
Vanshul97:fix/statsd-uds-socket-cleanup

Conversation

@Vanshul97
Copy link
Copy Markdown

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.ListenPacket fails because the stale socket file still exists:

starting to listen unixgram socket: listen unixgram /var/run/statsd.sock: bind: address already in use

The Close() method does remove the socket file, but it never runs during an unclean shutdown.

Fix

Added os.Remove(socketPath) before net.ListenPacket() in NewUDSServer(). 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

  • Added Test_NewUDSServer_CleansUpStaleSocket that simulates a crash (closes connection without removing socket file) and verifies a new server can start on the same path
  • Code compiles cleanly
  • Existing tests unaffected (linux-only build constraint)

@Vanshul97 Vanshul97 requested review from a team, dmitryax and jmacd as code owners April 17, 2026 19:19
@github-actions github-actions bot added the first-time contributor PRs made by new contributors label Apr 17, 2026
@github-actions
Copy link
Copy Markdown
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!

@github-actions github-actions bot added the receiver/statsd statsd related issues label Apr 17, 2026
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
@Vanshul97 Vanshul97 force-pushed the fix/statsd-uds-socket-cleanup branch from d56ab71 to 7eea7dd Compare April 17, 2026 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

first-time contributor PRs made by new contributors receiver/statsd statsd related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StatsD receiver not releasing unix socket

2 participants