Skip to content

Commit 7a80b5d

Browse files
authored
Merge pull request #36 from fsspec/timeouts
use aiohttp-retry to try again on specific request errors
2 parents 70a7f27 + 2afd642 commit 7a80b5d

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

ipfsspec/async_ipfs.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import asyncio
1010
import aiohttp
11+
import aiohttp_retry
1112

1213
from fsspec.asyn import AsyncFileSystem, sync, sync_wrapper
1314
from fsspec.exceptions import FSTimeoutError
@@ -147,12 +148,12 @@ def _raise_not_found_for_status(self, response, url):
147148
response.raise_for_status()
148149

149150

150-
151-
152151
async def get_client(**kwargs):
153-
timeout = aiohttp.ClientTimeout(sock_connect=1, sock_read=5)
154-
kwargs = {"timeout": timeout, **kwargs}
155-
return aiohttp.ClientSession(**kwargs)
152+
retry_options = aiohttp_retry.ExponentialRetry(
153+
attempts=5,
154+
exceptions={OSError, aiohttp.ServerDisconnectedError, asyncio.TimeoutError})
155+
retry_client = aiohttp_retry.RetryClient(raise_for_status=False, retry_options=retry_options)
156+
return retry_client
156157

157158

158159
def gateway_from_file(gateway_path, protocol="ipfs"):

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ dependencies = [
2323
"fsspec>=0.9.0",
2424
"requests",
2525
"aiohttp",
26+
"aiohttp-retry",
2627
"multiformats",
2728
"dag-cbor >= 0.2.2",
2829
"pure-protobuf >= 2.1.0, <3",

0 commit comments

Comments
 (0)