ipywidgets icon indicating copy to clipboard operation
ipywidgets copied to clipboard

Bug: Comm is already created / race condition

Open maartenbreddels opened this issue 2 years ago • 1 comments

Description

I sometimes see a message "Comm is already created"

Reproduce

Patch widget.py:

    @classmethod
    def _handle_control_comm_msg(cls, msg):
        # This shouldn't happen unless someone calls this method manually
        if cls._control_comm is None:
            raise RuntimeError('Control comm has not been properly opened')

        data = msg['content']['data']
        method = data['method']

        if method == 'request_states':
            import time

            time.sleep(4)  # go over the CONTROL_COMM_TIMEOUT

Trigger a code path to execute https://github.com/jupyter-widgets/ipywidgets/blob/74774dae5becb9f4781c3438a5fece1f8ca60415/packages/base-manager/src/manager-base.ts#L382

We will trigger the timeout, causing us to create the comms twice (the new and the old way).

The timeout of 4 seconds sounds extreme, but I see chrome (with dev console open) sometimes 'hanging' on websocket connections. The explicit timeout simulates this behaviour.

maartenbreddels avatar Aug 31 '22 13:08 maartenbreddels

Thanks for looking into this. I also see this sometimes in error messages people are posting.

jasongrout avatar Aug 31 '22 14:08 jasongrout