aim to correct resMSendRC current implementation #22324
Open
+59
−24
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.
Zig version
OS
Issues that might be related
How to reproduce
src/main.zig
test output
Expected behaviour
To be able to determine the IP address list correctly without TemporaryNameServerFailure error.
Solution
Firstly let me clarify that my experience with zig is literally 4 days, so review the pull request carefully in case I made some mistake or there's a better or more idiomatic way to do this. Debugging the previous error I arrived to the conclusion that the main issue was on the method resMSendRC, looking at the definition of this method can be noticed that two distinct buffers are passed to store the answer of the queries,
answers, and answer_bufs
. Later these two buffers are are accessed and written indistinctly inside the outer: while tag. During the whole loop iterations the value ofanswer_bufs
after the call torecvfrom(fd, answer_bufs[next], 0, &sa.any, &sl_copy)
was always[::1]:53
while the amount of name servers retrieved was more than one.I suspect the issue was in the allocation or the way the slices were passed, in some way the values of
answer[next]
remains the same during the iterations. To avoid that, I allocated a buffer inside this method and use that to store the value fromrecvfrom
instead, and later copy that to theanswers
array. As I say before I'm not so familiar with zig so maybe here there's an error that can be fixed easily without this amount of code.