Fix an infinite read loop with SRV record resolution on windows #25672
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.
Tentative fix for #25654
One effect of the simplification in #25105 was that it changed the c-ares resolver to invoke
RegisterOnReadableLocked
on all active fd's also now when SRV records are resolved. Notably, it does this from a callback that is invoked from the c-ares library during a call toares_process
, and it also clears the readable_registered_ flag before doing this. After thisares_process
call completes, we check if there are still more bytes to read on the socket and then continue looping on ares_process if so.On Windows,
RegisterOnReadableLocked
pre-allocates space forread_buf_
to read in bytes asynchronously viaRecvFrom
. Data is actually filled intoread_buf_
only when theRecvFrom
call completes and theOnIocpReadableLocked
callback is invoked. So because we are callingRegisterForOnReadableLocked
from a callback invoked fromares_process
, whenares_process
returns,read_buf_
has a non-zero length but doesn't actually have any readable data. Thus the loop where we continue callingares_process
so long asIsStillReadableLocked
returns true will never finish.read_buf_has_data_
is set true when we read in data fromRecvFrom
, and is then cleared after c-ares reads all received bytes out of it (this is the proper flag to check if there are still bytes remaining to be read).