Fix UDP retry condition: use $received_data flag instead of count($servers)#10
Open
mcfnord wants to merge 2 commits intosoftins:masterfrom
Open
Fix UDP retry condition: use $received_data flag instead of count($servers)#10mcfnord wants to merge 2 commits intosoftins:masterfrom
mcfnord wants to merge 2 commits intosoftins:masterfrom
Conversation
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>
Author
|
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. |
Owner
|
Thanks, I'll read through and understand these changes before merging, as they are non-trivial. |
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
count($servers) <= 1retry guard with an explicit$received_databoolean flagProblem with the count($servers) approach
The
count($servers) <= 1heuristic conflates two different things:?queryand?serverrequests,$serversis pre-populated with 1 entry (the target server), so<= 1correctly means "no response data received yet."?directoryrequests,$serversstarts at 0 and grows asCLM_SERVER_LISTpackets arrive. A directory server that legitimately has only one registered server will receive its full response, hit the trailing timeout, and still satisfycount($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:
Fix
An explicit
$received_dataflag is set totrueon the first successfully received packet, beforeprocess_received()is called. The retry and failure conditions check!$received_datainstead ofcount($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