react-vnc icon indicating copy to clipboard operation
react-vnc copied to clipboard

Error "Tried changing state of a disconnected RFB object" on automatic reconnection

Open marc-legendre opened this issue 1 year ago • 1 comments

Are you certain it's a bug?

  • [X] Yes, it looks like a bug

Are you sure this is not an issue in noVNC?

  • [X] It is not a noVNC issue

Is there an existing issue for this?

  • [X] I have searched existing issues, it hasn't been reported yet

Issue description

Hi there, I'm trying out this nice little project, and I noticed a small issue.

noVNC emits an error "Tried changing state of a disconnected RFB object" when VncScreen automatically tries to reconnect after a connection loss.

Details

It is an error to call rfb.disconnect() once rfb is in a disconnected state.

This happens when losing the connection to the server. Indeed, a call to connect() is scheduled without clearing rfb or connected. Then when connect() is called, it calls disconnect(), which calls rfb.disconnect().

Note: noVNC emits an error, but handles the situation gracefully.

Clearing rfb prevents this from happening:

diff --git i/src/lib/VncScreen.tsx w/src/lib/VncScreen.tsx
index af032d9..e73d3c9 100644
--- i/src/lib/VncScreen.tsx
+++ w/src/lib/VncScreen.tsx
@@ -160,6 +160,7 @@ const VncScreen: React.ForwardRefRenderFunction<VncScreenHandle, Props> = (props
         if (connected) {
             logger.info(`Unexpectedly disconnected from remote VNC, retrying in ${retryDuration / 1000} seconds.`);
 
+            setRfb(null);
             timeouts.current.push(setTimeout(connect, retryDuration));
         } else {
             logger.info(`Disconnected from remote VNC.`);

Intuitively, I'd also clear connected. But I am not entirely sure if I get connected right, since it is initialized to true when autoconnect is enabled. I find this puzzling :thinking:

marc-legendre avatar Jun 26 '24 17:06 marc-legendre

Hi @marc-legendre , thanks for reporting the issue. I somewhat understand what the issue is, but I can't think of how to fix it off the top of my head. I'll try to take a look at this during the weekend, in the meantime if you want to raise a PR for the fix please feel free to do so!

roerohan avatar Jun 27 '24 09:06 roerohan