Commit 412cb67
fix: close HTTPError to prevent ResourceWarning on Python 3.14 (#1133)
* fix: close HTTPError response to prevent ResourceWarning on Python 3.14
On Python 3.14, urllib.error.HTTPError objects that are not explicitly
closed produce a ResourceWarning during garbage collection. Since
HTTPError is both a URLError subclass and a response-like object
(inheriting from tempfile._TemporaryFileWrapper via addinfourl), it
must be closed to release the underlying resource.
This adds an explicit e.close() call in the except handler of
PyJWKClient.fetch_data() when the caught exception is an HTTPError.
Fixes #1128
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix: use BytesIO for HTTPError fp in test to fix Python 3.9 compatibility
On Python 3.9, HTTPError(fp=None).close() triggers a KeyError in
tempfile.SpooledTemporaryFile.__getattr__ because the internal 'file'
dict key doesn't exist. Using io.BytesIO(b"") as the fp argument
provides a valid file-like object that can be closed on all Python
versions.
Also adds CHANGELOG.rst entry for the HTTPError close fix.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
---------
Co-authored-by: Claude Opus 4.6 <[email protected]>1 parent 53e9381 commit 412cb67
3 files changed
Lines changed: 30 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
| 113 | + | |
| 114 | + | |
113 | 115 | | |
114 | 116 | | |
115 | 117 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
6 | | - | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
89 | 104 | | |
90 | 105 | | |
91 | 106 | | |
| |||
361 | 376 | | |
362 | 377 | | |
363 | 378 | | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
0 commit comments