diff --git a/src/aleph/config.py b/src/aleph/config.py index afafb9f28..8c378e40d 100644 --- a/src/aleph/config.py +++ b/src/aleph/config.py @@ -213,6 +213,8 @@ def get_defaults(): # Timeout for pinning operations (seconds) "timeout": 60, }, + # Timeout for file stat requests (seconds) + "stat_timeout": 30, }, "rabbitmq": { # Hostname of the RabbitMQ service. diff --git a/src/aleph/handlers/content/store.py b/src/aleph/handlers/content/store.py index e4c3f148f..4ad39a652 100644 --- a/src/aleph/handlers/content/store.py +++ b/src/aleph/handlers/content/store.py @@ -115,7 +115,8 @@ async def fetch_related_content( try: # The timeout of the aioipfs client does not seem to work, time out manually stats = await asyncio.wait_for( - ipfs_client.files.stat(f"/ipfs/{item_hash}"), 5 + ipfs_client.files.stat(f"/ipfs/{item_hash}"), + config.ipfs.stat_timeout.value, ) except aioipfs.InvalidCIDError as e: raise UnknownHashError( diff --git a/src/aleph/web/controllers/ipfs.py b/src/aleph/web/controllers/ipfs.py index 828d61379..1d63fb22f 100644 --- a/src/aleph/web/controllers/ipfs.py +++ b/src/aleph/web/controllers/ipfs.py @@ -53,10 +53,14 @@ async def ipfs_add_file(request: web.Request): # IPFS add returns the cumulative size and not the real file size. # We need the real file size here. - stats = await asyncio.wait_for( - ipfs_service.ipfs_client.files.stat(f"/ipfs/{cid}"), 5 - ) - size = stats["Size"] + try: + stats = await asyncio.wait_for( + ipfs_service.ipfs_client.files.stat(f"/ipfs/{cid}"), + config.ipfs.stat_timeout.value, + ) + size = stats["Size"] + except TimeoutError: + raise web.HTTPNotFound(reason="File not found on IPFS") with session_factory() as session: upsert_file(