Skip to content

ngclient: propagate non-timeout urllib3 connection errors#2964

Open
arpitjain099 wants to merge 1 commit into
theupdateframework:developfrom
arpitjain099:fix/urllib3-non-timeout-error
Open

ngclient: propagate non-timeout urllib3 connection errors#2964
arpitjain099 wants to merge 1 commit into
theupdateframework:developfrom
arpitjain099:fix/urllib3-non-timeout-error

Conversation

@arpitjain099

Copy link
Copy Markdown

Description of the changes being introduced by the pull request:

While reading the Urllib3Fetcher I noticed that _fetch() only handles the timeout case of MaxRetryError. When the reason is anything else (a TLS certificate error, for instance) the except block does not re-raise, so execution continues to the response.status check while response is still unbound. The caller then gets an UnboundLocalError about response instead 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 a DownloadError as 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

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>
@arpitjain099 arpitjain099 requested a review from a team as a code owner July 8, 2026 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant