Skip to content

Commit 97d5dda

Browse files
committed
http: only close connector if it is available
1 parent bb88a37 commit 97d5dda

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

fsspec/implementations/http.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,10 @@ def close_session(loop, session):
123123
return
124124
except (TimeoutError, FSTimeoutError):
125125
pass
126-
if session._connector is not None:
126+
connector = getattr(session, "_connector", None)
127+
if connector is not None:
127128
# close after loop is dead
128-
session._connector._close()
129+
connector._close()
129130

130131
async def set_session(self):
131132
if self._session is None:

fsspec/implementations/tests/test_http.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,25 @@ def test_put_file(server, tmp_path, method, reset_files):
475475
assert fs.cat(server + "/hey_3") == b"yyy"
476476

477477

478+
async def get_aiohttp():
479+
from aiohttp import ClientSession
480+
481+
return ClientSession()
482+
483+
484+
async def get_proxy():
485+
class ProxyClient:
486+
pass
487+
488+
return ProxyClient()
489+
490+
491+
@pytest.mark.parametrize("get_client", [get_aiohttp, get_proxy])
492+
def test_close(get_client):
493+
fs = fsspec.filesystem("http", skip_instance_cache=True)
494+
fs.close_session(None, asyncio.run(get_client()))
495+
496+
478497
@pytest.mark.xfail(
479498
condition=sys.flags.optimize > 1, reason="no docstrings when optimised"
480499
)

0 commit comments

Comments
 (0)