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 fe9235a commit 031816c
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 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:
return HTTPNotFound(reason="Invalid message reference")

Check warning on line 73 in src/aleph/vm/orchestrator/views/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/aleph/vm/orchestrator/views/__init__.py#L68-L73

Added lines #L68 - L73 were not covered by tests


async def run_code_from_hostname(request: web.Request) -> web.Response:
Expand Down Expand Up @@ -98,8 +101,10 @@ async def run_code_from_hostname(request: web.Request) -> web.Response:
try:
message_ref = ItemHash(await get_ref_from_dns(domain=f"_aleph-id.{request.host}"))
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 aiodns.error.DNSError:
return HTTPNotFound(reason="Invalid message reference")
except UnknownHashError:
return HTTPNotFound(reason="Invalid message reference")

Check warning on line 107 in src/aleph/vm/orchestrator/views/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/aleph/vm/orchestrator/views/__init__.py#L105-L107

Added lines #L105 - L107 were not covered by tests

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

0 comments on commit 031816c

Please sign in to comment.