Skip to content

Retry UDP request on timeout before giving up#7

Open
mcfnord wants to merge 1 commit intosoftins:masterfrom
mcfnord:udp-retry
Open

Retry UDP request on timeout before giving up#7
mcfnord wants to merge 1 commit intosoftins:masterfrom
mcfnord:udp-retry

Conversation

@mcfnord
Copy link
Copy Markdown

@mcfnord mcfnord commented Mar 28, 2026

Summary

  • Replaces the single 1.5s SO_RCVTIMEO with a 500ms timeout and up to 3 attempts
  • On timeout with no data received, the same request is re-fired and recvfrom waits again
  • Worst-case total wait time is unchanged (~1.5s), but a single dropped UDP packet is recovered automatically
  • Logs an error only on total failure (all attempts exhausted with no response)

Motivation

UDP is inherently lossy. The original code made one attempt and either succeeded or silently returned nothing to the client. Under any packet loss — even transient — the directory or server query would fail completely. The retry loop makes the behaviour consistent with what users expect from a web page fetching live server lists.

Test plan

  • Verified baseline RTT to anygenre1.jamulus.io:22124 is ~142ms, well within the 500ms window
  • Applied iptables 40% random UDP drop rule and ran 20 requests: attempt-2 recoveries worked correctly, attempt-3 recoveries worked correctly, total-failure rate matched expected probability
  • Removed drop rule and confirmed normal operation restored

Replace the single 1.5s socket timeout with a 500ms timeout and up to
3 attempts. If no data is received within the window, the same request
is re-sent. This recovers from dropped UDP packets without increasing
the worst-case wait time beyond the original 1.5s.
@mcfnord
Copy link
Copy Markdown
Author

mcfnord commented Mar 28, 2026

I haven't run this in production. Will do so and report results here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant