ngclient: propagate non-timeout urllib3 connection errors#2964
Open
arpitjain099 wants to merge 1 commit into
Open
ngclient: propagate non-timeout urllib3 connection errors#2964arpitjain099 wants to merge 1 commit into
arpitjain099 wants to merge 1 commit into
Conversation
Urllib3Fetcher._fetch caught MaxRetryError and only re-raised it (as SlowRetrievalError) when the reason was a timeout. For any other reason, such as a TLS certificate error, it fell through to the response.status check with response still unbound, so the caller saw an UnboundLocalError instead of the real connection error. Re-raise the original error when the reason is not a timeout, so fetch() wraps the meaningful error in a DownloadError as documented. Add a regression test covering a non-timeout MaxRetryError. Signed-off-by: arpitjain099 <arpitjain099@gmail.com>
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.
Description of the changes being introduced by the pull request:
While reading the Urllib3Fetcher I noticed that
_fetch()only handles the timeout case ofMaxRetryError. When the reason is anything else (a TLS certificate error, for instance) the except block does not re-raise, so execution continues to theresponse.statuscheck whileresponseis still unbound. The caller then gets anUnboundLocalErroraboutresponseinstead of the actual connection error, which makes real failures hard to diagnose.This re-raises the original error when the reason is not a timeout, so
fetch()wraps the meaningful error in aDownloadErroras documented in FetcherInterface. I added a regression test that drives a non-timeout MaxRetryError and checks the underlying cause is preserved. The full test suite passes locally with tox.Fixes: non-timeout connection errors surfacing as UnboundLocalError