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

When worker stops the API keeps returning 202 #27

Open
krassowski opened this issue Aug 27, 2024 · 1 comment
Open

When worker stops the API keeps returning 202 #27

krassowski opened this issue Aug 27, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@krassowski
Copy link
Collaborator

Description

When worker stops due to an error the API will keep returning 202 rather than show an error. This means that the client will wait for execution in an infinite loop

Reproduce

one way to reproduce it is to programatically stop the pycrdt_websocket server:

[D 2024-08-27 09:36:09.061 ServerApp.jupyter_server_nb_model] Starting worker to process execution requests of kernel b9e05053-c3c9-4865-861f-77bac0f548c6…
[D 2024-08-27 09:36:09.061 ServerApp.jupyter_server_nb_model] Processing execution request a6f69c19-1435-4616-91d6-547e25c722d2 for kernel b9e05053-c3c9-4865-861f-77bac0f548c6…
[D 2024-08-27 09:36:09.061 ServerApp.jupyter_server_nb_model] a6f69c19-1435-4616-91d6-547e25c722d2  {'document_id': 'json:notebook:e70c9a57-dfa3-45ff-9509-88fccda8da2a', 'cell_id': '885916f4-16de-4c00-9873-56795ba1734f'}
[D 2024-08-27 09:36:09.061 ServerApp.jupyter_server_nb_model] Stopping execution requests worker for kernel b9e05053-c3c9-4865-861f-77bac0f548c6Traceback (most recent call last):
      File "/home/jupyter/notebook-env/lib/python3.11/site-packages/jupyter_server_nbmodel/handlers.py", line 275, in _kernel_worker
        results[uid] = await _execute_snippet(
                       ^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/jupyter/notebook-env/lib/python3.11/site-packages/jupyter_server_nbmodel/handlers.py", line 223, in _execute_snippet
        ycell = await _get_ycell(ydoc, metadata)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/jupyter/notebook-env/lib/python3.11/site-packages/jupyter_server_nbmodel/handlers.py", line 101, in _get_ycell
        notebook: YNotebook | None = await ydoc.get_document(room_id=document_id, copy=False)
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/jupyter/notebook-env/lib/python3.11/site-packages/jupyter_server_ydoc/app.py", line 170, in get_document
        room = await self.ywebsocket_server.get_room(room_id)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/jupyter/notebook-env/lib/python3.11/site-packages/jupyter_server_ydoc/websocketserver.py", line 132, in get_room
        await self.start_room(room)
      File "/home/jupyter/notebook-env/lib/python3.11/site-packages/pycrdt_websocket/websocket_server.py", line 96, in start_room
        raise RuntimeError(
    RuntimeError: The WebsocketServer is not running: use `async with websocket_server:` or `await websocket_server.start()`

Expected behavior

Error is propagated to the API

@krassowski krassowski added the bug Something isn't working label Aug 27, 2024
@krassowski
Copy link
Collaborator Author

A simple fix would to to set results[uid] to an a dict containing an "error" key in the except group of:

results[uid] = await _execute_snippet(
client, ydoc, snippet, metadata, partial(_stdin_hook, kernel_id, uid, pending_input)
)
queue.task_done()
get_logger().debug(f"Execution request {uid} processed for kernel {kernel_id}.")
except (asyncio.CancelledError, KeyboardInterrupt, RuntimeError) as e:
get_logger().debug(
f"Stopping execution requests worker for kernel {kernel_id}…", exc_info=e
)
# Empty the queue
while not queue.empty():
queue.task_done()
to_raise = e
break

As this would then correctly set 500 status:

if r is None:
self.set_status(202)
self.finish("{}")
else:
if "error" in r:
self.set_status(500)
self.log.debug(f"{r}")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant