novnc / websockify

Websockify is a WebSocket to TCP proxy/bridge. This allows a browser to connect to any application/server/service.
GNU Lesser General Public License v3.0
3.95k stars 780 forks source link

novnc session getting disconnected after 30 min if left idle #562

Closed amule0317 closed 1 year ago

amule0317 commented 1 year ago

I am using novnc websockify library to connect vnc console. I am able to connect to the console, but console get disconnected after 30 min if it is left idle (i.e no input is provided to console)

While debugging the websockify, below is the analysis,

When do_proxy(websockify/websocketproxy.py) method is called

if cqueue or c_pend: wlist.append(self.request)
try:
    ins, outs, excepts = select.select(rlist, wlist, [], 1)
except (select.error, OSError):
    exc = sys.exc_info()[1]

For 30 min it return ins, outs, excepts as empty list. 2023-09-16 07:07:03.816 3843 INFO websockify.websocketproxy [req-****] Value of ins is [] 2023-09-16 07:07:03.816 3843 INFO websockify.websocketproxy [req-****] Value of outs is []

After 30 min, we recieve below ins and outs 2023-09-16 07:07:04.631 3843 INFO websockify.websocketproxy [req-****] Value of ins is [<websockify.websockifyserver.CompatibleWebSocket object at 0x7fad0042a2e0>] 2023-09-16 07:07:04.631 3843 INFO websockify.websocketproxy [req-****] Value of outs is [] and then console get disconnected.

we analyzed that do_proxy method calls recv_frames(websockify/websockifyserver.py) method which internally call _recv_frames(websockify/websocket.py)

def _recv_frames(self):
# Fetches more data and decodes the frames
if not self._recv():
        if self.close_code is None:
            self.close_code = 1006
            self.close_reason = "Connection closed abnormally"
            self._sent_close = self._received_close = True
        self._close()
        return False

This calls self._recv()

def _recv(self):
    # Fetches more data from the socket to the buffer
    assert self.socket is not None

    while True:
        try:
            **data = self.socket.recv(4096)**
        except (socket.error, OSError):
            exc = sys.exc_info()[1]
            if hasattr(exc, 'errno'):
                err = exc.errno
            else:
                err = exc[0]

            if err == errno.EWOULDBLOCK:
                raise WebSocketWantReadError

            raise

        if len(data) == 0:
            return False

Here after 30 min value of data is coming as None and it then returns false. and then it raise 1006 error.

Any idea, How the session is getting disconnected after 30 min.

CendioOssman commented 1 year ago

It sounds like you have a firewall or something killing connections if they are idle.

What does the browser console on the client say?

amule0317 commented 1 year ago
Screenshot 2023-02-10 at 10 20 15 PM (1)

We are seeing this error Server Disconnected (Code : 1006)

CendioOssman commented 1 year ago

We need to see the details from the Javascript console. The browsers unfortunately don't tell us enough that we can present in the UI.

poovannan89 commented 1 year ago

@CendioOssman Please find Javascript console details. Just masked IPs for security purpose. The code we use is https://github.com/novnc/noVNC/blob/master/vnc_lite.html. But, we have not pulled in latest changes of this file and its the same for many years now. Not sure if this error has any significance of vnc_lite.html version. image

CendioOssman commented 1 year ago

Thanks.

Not many more details there, but we can see that it wasn't initiated from noVNC at least. And since the browser didn't log anything extra, I would assume it was network initiated.

So unfortunately, it's not something we can really help you with. There is something on your network killing those connections. Likely a proxy or firewall. You'll need to figure out it is and get someone to adjust it to not kill these connections.