shared: don't infinitely retry on I/O timeout #8
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.
After the introduction of shared clients, we received reports of excessive CPU usage. Through a debug logging build, the cause was identified to be mishandling of "i/o timeout" errors, which are returned from read (or write) calls when the read (or write) deadline of a connection are exceeded.
In the existing code, once we hit such an I/O timeout, the receiving goroutine was calling 'ReadMsg' in a busy loop, as the connection was not closed, but reads were not succeeding either. No useful work was performed anymore, until a further attempt at sending would reset the read deadline (c.f. the 'SendContext' method). This, however, depends on whether the retry occurs on the same five tuple, which isn't guaranteed. Indeed, it seems more than conceivable that a DNS client might retry with a different source port.
To remedy the issue, this patch adds a check for the exceeded deadline. Unceremoniously, we shut down the handling goroutine if we hit this I/O timeout. This then closes the connection, which also shuts down the receiving goroutine.
Reported-by: John Watson john@dctrwatson.com