Skip to content

Commit

Permalink
🐛 fix attempt to send ping frame in our discrete background idle watc…
Browse files Browse the repository at this point in the history
…her when the connection has just been closed
  • Loading branch information
Ousret committed Oct 30, 2024
1 parent 6e60380 commit 6a07d33
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2.11.907 (2024-10-30)
=====================

- Fixed attempt to send ping frame in our discrete background idle watcher when the connection has just been closed.

2.11.906 (2024-10-26)
=====================

Expand Down
3 changes: 3 additions & 0 deletions src/urllib3/_async/connectionpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ async def idle_conn_watch_task(
return
try:
async for conn in pool.pool.iter_idle():
if conn.is_connected is False:
continue

now = time.monotonic()
last_used = conn.last_used_at
idle_delay = now - last_used
Expand Down
5 changes: 5 additions & 0 deletions src/urllib3/backend/_async/hface.py
Original file line number Diff line number Diff line change
Expand Up @@ -1595,10 +1595,15 @@ async def ping(self) -> None: # type: ignore[override]
if self.sock is None or self._protocol is None:
return

if self._protocol.has_expired():
return

try:
self._protocol.ping()
except NotImplementedError: # http/1 case.
return
except self._protocol.exceptions():
return

while True:
ping_frame = self._protocol.bytes_to_send()
Expand Down
7 changes: 6 additions & 1 deletion src/urllib3/backend/hface.py
Original file line number Diff line number Diff line change
Expand Up @@ -1652,9 +1652,14 @@ def ping(self) -> None:
if self.sock is None or self._protocol is None:
return

if self._protocol.has_expired():
return

try:
self._protocol.ping()
except NotImplementedError: # http/1 case.
except NotImplementedError:
return
except self._protocol.exceptions():
return

while True:
Expand Down
3 changes: 3 additions & 0 deletions src/urllib3/connectionpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ def idle_conn_watch_task(

try:
for conn in pool.pool.iter_idle():
if conn.is_connected is False:
continue

now = time.monotonic()
last_used = conn.last_used_at

Expand Down

0 comments on commit 6a07d33

Please sign in to comment.