Skip to content

Commit

Permalink
Merge pull request #36 from fsspec/timeouts
Browse files Browse the repository at this point in the history
use aiohttp-retry to try again on specific request errors
  • Loading branch information
d70-t committed Sep 19, 2024
2 parents 70a7f27 + 2afd642 commit 7a80b5d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
11 changes: 6 additions & 5 deletions ipfsspec/async_ipfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import asyncio
import aiohttp
import aiohttp_retry

from fsspec.asyn import AsyncFileSystem, sync, sync_wrapper
from fsspec.exceptions import FSTimeoutError
Expand Down Expand Up @@ -147,12 +148,12 @@ def _raise_not_found_for_status(self, response, url):
response.raise_for_status()




async def get_client(**kwargs):
timeout = aiohttp.ClientTimeout(sock_connect=1, sock_read=5)
kwargs = {"timeout": timeout, **kwargs}
return aiohttp.ClientSession(**kwargs)
retry_options = aiohttp_retry.ExponentialRetry(
attempts=5,
exceptions={OSError, aiohttp.ServerDisconnectedError, asyncio.TimeoutError})
retry_client = aiohttp_retry.RetryClient(raise_for_status=False, retry_options=retry_options)
return retry_client


def gateway_from_file(gateway_path, protocol="ipfs"):
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dependencies = [
"fsspec>=0.9.0",
"requests",
"aiohttp",
"aiohttp-retry",
"multiformats",
"dag-cbor >= 0.2.2",
"pure-protobuf >= 2.1.0, <3",
Expand Down

0 comments on commit 7a80b5d

Please sign in to comment.