Skip to content

Fix UDP retry condition: use $received_data flag instead of count($servers)#10

Open
mcfnord wants to merge 2 commits intosoftins:masterfrom
mcfnord:retry-with-received-flag
Open

Fix UDP retry condition: use $received_data flag instead of count($servers)#10
mcfnord wants to merge 2 commits intosoftins:masterfrom
mcfnord:retry-with-received-flag

Conversation

@mcfnord
Copy link
Copy Markdown

@mcfnord mcfnord commented Mar 31, 2026

Summary

  • Replaces count($servers) <= 1 retry guard with an explicit $received_data boolean flag
  • Retry now triggers only when zero bytes were received before the timeout — not based on how many servers are in the list

Problem with the count($servers) approach

The count($servers) <= 1 heuristic conflates two different things:

  • For ?query and ?server requests, $servers is pre-populated with 1 entry (the target server), so <= 1 correctly means "no response data received yet."
  • For ?directory requests, $servers starts at 0 and grows as CLM_SERVER_LIST packets arrive. A directory server that legitimately has only one registered server will receive its full response, hit the trailing timeout, and still satisfy count($servers) <= 1 — triggering an unnecessary retry and adding ~500ms latency.

Production logs confirm this is not hypothetical. Several real directory endpoints regularly return exactly one server:

jazz.jamulus.io:22224     servers=1
jazz.jamulus.io:22624     servers=1
rock.jamulus.io:22624     servers=1
classical.jamulus.io:22224 servers=1
classical.jamulus.io:22624 servers=1

Fix

An explicit $received_data flag is set to true on the first successfully received packet, before process_received() is called. The retry and failure conditions check !$received_data instead of count($servers) <= 1.

This cleanly separates "did we receive anything?" from "how many servers were listed?"

Relationship to PR #7

This is a corrected version of the retry logic introduced in #7. The motivation and overall structure are the same.

🤖 Generated with Claude Code

jrd and others added 2 commits March 28, 2026 22:32
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.
…ers)

The original count($servers) <= 1 heuristic fails for directory servers
that legitimately have only one registered server: data is received
successfully but the trailing timeout still triggers an unnecessary retry,
adding ~500ms latency. Using an explicit $received_data flag correctly
distinguishes "no response at all" (retry) from "stream ended normally"
(stop).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@mcfnord
Copy link
Copy Markdown
Author

mcfnord commented Mar 31, 2026

I bet if you run servers.php in the same datacenter as the directory servers themselves, the response loss rate would be nearly zero. From California, the loss rate is noticeable. In 14 days I'll have logs that reveal precise numbers about this PR's efficacy.

@softins
Copy link
Copy Markdown
Owner

softins commented Mar 31, 2026

Thanks, I'll read through and understand these changes before merging, as they are non-trivial.

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.

2 participants