Skip to content

Commit

Permalink
Fix: Unkwnown hashes raised exception
Browse files Browse the repository at this point in the history
Problem: Many crawlers called URLs that do not exist on CRNs.

The current implementation raises an error when the hash of the VM cannot be found, which fills the logs on Sentry.

Solution: Return an HTTP Not Found status instead.
  • Loading branch information
hoh committed Apr 26, 2024
1 parent 84614a5 commit 1590ee3
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/aleph/vm/orchestrator/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,12 @@ async def run_code_from_path(request: web.Request) -> web.Response:
path = request.match_info["suffix"]
path = path if path.startswith("/") else f"/{path}"

message_ref = ItemHash(request.match_info["ref"])
pool: VmPool = request.app["vm_pool"]
return await run_code_on_request(message_ref, path, pool, request)
try:
message_ref = ItemHash(request.match_info["ref"])
pool: VmPool = request.app["vm_pool"]
return await run_code_on_request(message_ref, path, pool, request)
except UnknownHashError as error:
raise HTTPNotFound(reason="Invalid message reference") from error


async def run_code_from_hostname(request: web.Request) -> web.Response:
Expand Down Expand Up @@ -100,6 +103,8 @@ async def run_code_from_hostname(request: web.Request) -> web.Response:
logger.debug(f"Using DNS TXT record to obtain '{message_ref}'")
except aiodns.error.DNSError as error:
raise HTTPNotFound(reason="Invalid message reference") from error
except UnknownHashError as error:
raise HTTPNotFound(reason="Invalid message reference") from error

pool = request.app["vm_pool"]
return await run_code_on_request(message_ref, path, pool, request)
Expand Down

0 comments on commit 1590ee3

Please sign in to comment.