Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix errors cascade on Websocket.prepare() error #472

Merged
merged 1 commit into from
Nov 17, 2023

Conversation

olethanh
Copy link
Collaborator

@olethanh olethanh commented Nov 16, 2023

This fix the error cascade that happened when opening the logs endpoint not as websocket. This was problematic because it returned to the http client a 500 error instead of the actual error code and message

To reproduce

Error that happened before
2023-11-16 16:16:58,089 | ERROR | Error handling request Traceback (most recent call last):
  File "/home/ubuntu/remote-aleph/src/aleph/vm/orchestrator/views/operator.py", line 147, in stream_logs
    await ws.prepare(request)
  File "/home/ubuntu/.virtualenvs/aleph-vm/lib/python3.10/site-packages/aiohttp/web_ws.py", line 137, in prepare
    protocol, writer = self._pre_start(request)
  File "/home/ubuntu/.virtualenvs/aleph-vm/lib/python3.10/site-packages/aiohttp/web_ws.py", line 232, in _pre_start
    headers, protocol, compress, notakeover = self._handshake(request)
  File "/home/ubuntu/.virtualenvs/aleph-vm/lib/python3.10/site-packages/aiohttp/web_ws.py", line 149, in _handshake
    raise HTTPBadRequest(
aiohttp.web_exceptions.HTTPBadRequest: Bad Request

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ubuntu/remote-aleph/src/aleph/vm/orchestrator/views/operator.py", line 157, in stream_logs
    await ws.close()
  File "/home/ubuntu/.virtualenvs/aleph-vm/lib/python3.10/site-packages/aiohttp/web_ws.py", line 337, in close
    raise RuntimeError("Call .prepare() first")
RuntimeError: Call .prepare() first

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ubuntu/.virtualenvs/aleph-vm/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
    resp = await request_handler(request)
  File "/home/ubuntu/.virtualenvs/aleph-vm/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/home/ubuntu/.virtualenvs/aleph-vm/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/home/ubuntu/remote-aleph/src/aleph/vm/orchestrator/supervisor.py", line 46, in server_version_middleware
    resp: web.StreamResponse = await handler(request)
  File "/home/ubuntu/remote-aleph/src/aleph/vm/orchestrator/views/operator.py", line 159, in stream_logs
    execution.vm.fvm.log_queues.remove(queue)
ValueError: list.remove(x): x not in list

@olethanh olethanh requested a review from hoh November 16, 2023 16:56
This fix the error cascade that happened when opening the logs endpoint
not as websocket. This was problematic because it returned to the http
client a 500 error instead of the actual error code and message

To reproduce
* start aleph supervisor
* open in Firefox: http://localhost:4020/vm/3fc0aa9569da840c43e7bd2033c3c580abb46b007527d6d20f2d4e98e867f7af
* then in another tab http://localhost:4020/control/machine/3fc0aa9569da840c43e7bd2033c3c580abb46b007527d6d20f2d4e98e867f7af/logs

Error that happened before
2023-11-16 16:16:58,089 | ERROR | Error handling request
Traceback (most recent call last):
  File "/home/ubuntu/remote-aleph/src/aleph/vm/orchestrator/views/operator.py", line 147, in stream_logs
    await ws.prepare(request)
  File "/home/ubuntu/.virtualenvs/aleph-vm/lib/python3.10/site-packages/aiohttp/web_ws.py", line 137, in prepare
    protocol, writer = self._pre_start(request)
  File "/home/ubuntu/.virtualenvs/aleph-vm/lib/python3.10/site-packages/aiohttp/web_ws.py", line 232, in _pre_start
    headers, protocol, compress, notakeover = self._handshake(request)
  File "/home/ubuntu/.virtualenvs/aleph-vm/lib/python3.10/site-packages/aiohttp/web_ws.py", line 149, in _handshake
    raise HTTPBadRequest(
aiohttp.web_exceptions.HTTPBadRequest: Bad Request

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ubuntu/remote-aleph/src/aleph/vm/orchestrator/views/operator.py", line 157, in stream_logs
    await ws.close()
  File "/home/ubuntu/.virtualenvs/aleph-vm/lib/python3.10/site-packages/aiohttp/web_ws.py", line 337, in close
    raise RuntimeError("Call .prepare() first")
RuntimeError: Call .prepare() first

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ubuntu/.virtualenvs/aleph-vm/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
    resp = await request_handler(request)
  File "/home/ubuntu/.virtualenvs/aleph-vm/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/home/ubuntu/.virtualenvs/aleph-vm/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/home/ubuntu/remote-aleph/src/aleph/vm/orchestrator/supervisor.py", line 46, in server_version_middleware
    resp: web.StreamResponse = await handler(request)
  File "/home/ubuntu/remote-aleph/src/aleph/vm/orchestrator/views/operator.py", line 159, in stream_logs
    execution.vm.fvm.log_queues.remove(queue)
ValueError: list.remove(x): x not in list
@olethanh olethanh force-pushed the olethanh-fix-websocket-log-cascade-error branch from ae5ddc9 to 9229e72 Compare November 17, 2023 09:22
@olethanh
Copy link
Collaborator Author

Rebased ontp main to fix the conflicts

@hoh hoh added this pull request to the merge queue Nov 17, 2023
Merged via the queue into main with commit 5daf33a Nov 17, 2023
15 of 18 checks passed
@Psycojoker Psycojoker deleted the olethanh-fix-websocket-log-cascade-error branch July 24, 2024 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants