Ensure that the context cancel and deadline hit are respected and the related errors properly propagated #188
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.
This PR improves the behaviour of how the context is handled in HTTPPing.
Currently, if a context is cancelled, the HTTPPing will keep trying executing the requests, failing them, to return at the end a timeout error, therefore misreporting the reason for which the requests are actually failing.
On top of this, if a number of pings passed before the context got cancelled or the deadline was hit, the error will not be reported at all, making it hard for the caller to understand if the operation was succesful or not.
In my specific case I need to ensure that if I don't get a response within 30/60 seconds the speedtest terminates and reports the reason for the termination and in case it's a timeout it doesn't report general errors.
The PR ensure that if a context cancelled or a deadline hit, the code ping terminates and returns whatever latencies it collected, also returning the appropriate error.
This PR is only for HTTPPing but TCPPing has the same issue, not sure if it applies to ICMPPing but it might be the same there.