Skip to content

Commit

Permalink
fix: Exit on communication failure (#429)
Browse files Browse the repository at this point in the history
fixes #430

Often when rerunning component creation, an error containing "Stream is
already completed, no further calls are allowed" comes up
```
Error rendering __main__.test_component
Traceback (most recent call last):
  File "/Users/josephnumainville/Documents/deephaven-core/.venv/lib/python3.10/site-packages/deephaven/ui/object_types/ElementMessageStream.py", line 159, in _render
    self._send_document_update(node, state)
  File "/Users/josephnumainville/Documents/deephaven-core/.venv/lib/python3.10/site-packages/deephaven/ui/object_types/ElementMessageStream.py", line 355, in _send_document_update
    self._connection.on_data(payload.encode(), new_objects)
  File "/Users/josephnumainville/Documents/deephaven-core/.venv/lib/python3.10/site-packages/deephaven_internal/plugin/object/__init__.py", line 47, in on_data
    self._wrapped.onData(payload, [javaify(ref) for ref in references])
RuntimeError: io.deephaven.plugin.type.ObjectCommunicationException: java.lang.IllegalStateException: Stream is already completed, no further calls are allowed
...
```

This doesn't need to raise an exception to the user as this is just the
previous component's message stream signaling it is closed, but it does
need to exit so it doesn't keep trying to hit the message stream.
  • Loading branch information
jnumainville authored May 10, 2024
1 parent ff7f769 commit 0e96ef4
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion plugins/ui/src/deephaven/ui/object_types/ElementMessageStream.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import io
import json
import sys

from jsonrpc import JSONRPCResponseManager, Dispatcher
import logging
import threading
Expand Down Expand Up @@ -119,6 +121,11 @@ class ElementMessageStream(MessageStream):
Captured ExecutionContext for this stream, to wrap all user code.
"""

_is_closed: bool
"""
Whether or not the stream is closed. If closed, no more messages can be sent, and this component should exit.
"""

def __init__(self, element: Element, connection: MessageStream):
"""
Create a new ElementMessageStream. Renders the element in a render context, and sends the rendered result to the
Expand All @@ -142,6 +149,7 @@ def __init__(self, element: Element, connection: MessageStream):
self._is_dirty = False
self._render_state = _RenderState.IDLE
self._exec_context = get_exec_ctx()
self._is_closed = False

def _render(self) -> None:
logger.debug("ElementMessageStream._render")
Expand Down Expand Up @@ -240,7 +248,7 @@ def start(self) -> None:
self._connection.on_data(b"", [])

def on_close(self) -> None:
pass
self._is_closed = True

def on_data(self, payload: bytes, references: list[Any]) -> None:
"""
Expand Down Expand Up @@ -352,4 +360,9 @@ def _send_document_update(
logger.debug("Registering callable %s", callable_id)
dispatcher[callable_id] = wrap_callable(callable)
self._dispatcher = dispatcher
if self._is_closed:
# The connection is closed, so this component will not update anymore
# delete the context so the objects in the collected scope are released
del self._context
sys.exit()
self._connection.on_data(payload.encode(), new_objects)

0 comments on commit 0e96ef4

Please sign in to comment.