Skip to content

Commit 56402cd

Browse files
authored
Force refresh if session was closed (#1002)
1 parent a34eac9 commit 56402cd

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- "3.12"
1616
- "3.13"
1717
- "3.14"
18-
aiobotocore-version: [">=2.5.4,<2.6.0", "<3.0.0", "<4.0.0"]
18+
aiobotocore-version: [">=2.19.0,<2.20.0", "<3.0.0", "<4.0.0"]
1919

2020
env:
2121
BOTO_CONFIG: /dev/null

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
aiobotocore>=2.5.4,<4.0.0
1+
aiobotocore>=2.19.0,<4.0.0
22
fsspec==2026.1.0
33
aiohttp!=4.0.0a0, !=4.0.0a1

s3fs/core.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,12 @@ async def set_session(self, refresh=False, kwargs={}):
519519
>>> s3.connect(refresh=True) # doctest: +SKIP
520520
"""
521521
if self._s3 is not None and not refresh:
522-
return self._s3
522+
hsess = getattr(getattr(self._s3, "_endpoint", None), "http_session", None)
523+
if hsess is not None:
524+
if all(_.closed for _ in hsess._sessions.values()):
525+
refresh = True
526+
if not refresh:
527+
return self._s3
523528
logger.debug("Setting up s3fs instance")
524529

525530
client_kwargs = self.client_kwargs.copy()

s3fs/tests/test_s3fs.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3068,3 +3068,20 @@ def test_find_missing_ls(s3):
30683068
listed_no_cache = s3_no_cache.ls(BASE, detail=False)
30693069

30703070
assert set(listed_cached) == set(listed_no_cache)
3071+
3072+
3073+
def test_session_close():
3074+
async def run_program(run):
3075+
s3 = s3fs.S3FileSystem(anon=True, asynchronous=True)
3076+
session = await s3.set_session()
3077+
files = await s3._ls(
3078+
"s3://noaa-hrrr-bdp-pds/hrrr.20140730/conus/"
3079+
) # Random open data store
3080+
print(f"Number of files {len(files)}")
3081+
await session.close()
3082+
3083+
import aiobotocore.httpsession
3084+
3085+
aiobotocore.httpsession.AIOHTTPSession
3086+
asyncio.run(run_program(True))
3087+
asyncio.run(run_program(False))

0 commit comments

Comments
 (0)