Skip to content

Commit 1e3c3b1

Browse files
authored
Merge pull request #13 from fsspec/FileNotFound
don't retry if object is known to be missing
2 parents 17ff601 + ed3687b commit 1e3c3b1

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

ipfsspec/async_ipfs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ async def _gw_op(self, op):
202202
if state.speedup(time.monotonic() - now):
203203
logger.debug("%s speedup", gw)
204204
return res
205+
except FileNotFoundError: # early exit if object doesn't exist
206+
raise
205207
except (RequestsTooQuick, aiohttp.ClientResponseError, asyncio.TimeoutError) as e:
206208
state.backoff()
207209
logger.debug("%s backoff %s", gw, e)

test/test_async_fallback.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
class MockGateway(AsyncIPFSGatewayBase):
88
def __init__(self, objects):
99
self.objects = objects
10+
self.request_count = 0
1011

1112
async def cid_get(self, path, session, headers=None, **kwargs):
13+
self.request_count += 1
1214
try:
1315
return self.objects[path]
1416
except KeyError:
@@ -71,3 +73,19 @@ async def test_backoff_use_faster_server(session):
7173
obj = await gw.cid_get("QmTz3oc4gdpRMKP2sdGUPZTAGRngqjsi99BPoztyP53JMM", session)
7274
assert obj == "zapp"
7375
assert gws[0].request_count < gws[1].request_count
76+
77+
78+
@pytest.mark.asyncio
79+
async def test_stop_on_not_found(session):
80+
objects = {
81+
"QmTz3oc4gdpRMKP2sdGUPZTAGRngqjsi99BPoztyP53JMM": "zapp",
82+
}
83+
gws = [
84+
MockGateway(objects),
85+
MockGateway(objects)
86+
]
87+
gw = MultiGateway(gws)
88+
89+
with pytest.raises(FileNotFoundError):
90+
await gw.cid_get("QmTz3oc4gdpRMKP2sdGUPZTAGRngqjsi99BPoztyP53JMM/not_there", session)
91+
assert gws[1].request_count == 0

0 commit comments

Comments
 (0)