Recover from UDS socket loss by making BadSocketError retryable#330
Open
joshuay03 wants to merge 1 commit into
Open
Recover from UDS socket loss by making BadSocketError retryable#330joshuay03 wants to merge 1 commit into
BadSocketError retryable#330joshuay03 wants to merge 1 commit into
Conversation
joshuay03
force-pushed
the
uds-reconnect-on-bad-socket
branch
3 times, most recently
from
June 2, 2026 01:19
1479786 to
4f9e1af
Compare
UDSConnection raises BadSocketError when sendmsg_nonblock hits ECONNREFUSED, ECONNRESET, or ENOENT, but Connection#write's retry list did not include it, so the socket was never closed and every subsequent send failed the same way for the lifetime of the process. Introduce Connection::RetryableError and make BadSocketError inherit from it. Connection#write now closes and reconnects before retrying.
joshuay03
force-pushed
the
uds-reconnect-on-bad-socket
branch
from
June 2, 2026 01:23
4f9e1af to
8d2743d
Compare
BadSocketError retryable
joshuay03
marked this pull request as ready for review
June 2, 2026 01:24
There was a problem hiding this comment.
Pull request overview
This PR makes UDS socket failures recoverable by introducing a Connection::RetryableError base class, making UDSConnection::BadSocketError inherit from it, and teaching Connection#write to retry (close + reconnect) when that error occurs—preventing long-lived “wedged” sockets after a Datadog Agent restart.
Changes:
- Add
Datadog::Statsd::Connection::RetryableErrorand retry it inConnection#write. - Make
Datadog::Statsd::UDSConnection::BadSocketErrorinherit fromRetryableError(so UDS send failures trigger reconnect). - Update UDS specs to assert successful retry/close behavior and adjust telemetry/logging expectations; add changelog entry.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| lib/datadog/statsd/connection.rb | Introduces RetryableError and retries it in #write by closing and reconnecting once. |
| lib/datadog/statsd/uds_connection.rb | Makes BadSocketError retryable by inheriting from RetryableError. |
| spec/statsd/uds_connection_spec.rb | Converts previously pending/negative cases into assertions for retry, close-on-reconnect, logging, and telemetry. |
| spec/integrations/connection_edge_case_spec.rb | Updates integration coverage to assert the new retry/close behavior and logging for UDS edge cases. |
| CHANGELOG.md | Documents the UDS recovery bugfix under “Unreleased” and adds reference links. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
We ran into this at @buildkite when the Datadog Agent restarted on one of our nodes: every
Datadog::Statsdinstance in our Ruby process stayed wedged on the dead socket fd and dropped custom metrics until the app restarted.UDSConnection#send_messagewrapsErrno::ECONNREFUSED,Errno::ECONNRESET, andErrno::ENOENTasBadSocketError, butConnection#write's retry list did not include it, so the socket was never closed.This PR introduces
Connection::RetryableError, makesBadSocketErrorinherit from it, and adds it to the retry list. The existing TODO inUDSConnection#send_messageand the# FIXME: BadSocketError is not correctly caught by Connection class to retrynotes in the UDS specs already recommended this shape; the previouslypending: trueand "does not correctly retry" specs flip to positive assertions.