sibson / vncdotool

A command line VNC client and python library
Other
451 stars 120 forks source link

Bug in client.disconnect() #263

Closed MrNom4ik closed 1 year ago

MrNom4ik commented 1 year ago

vncdotool version vncdotool==1.0.0 twisted==22.10.0

VNC server and version different servers

Steps to reproduce

client = connect(f"{host}::{port}")
client.disconnect()

Expected result Normal disconnect from the server

Which erroneous result did you get instead

Unhandled error in Deferred:

Traceback (most recent call last):
  File "C:\Users\User\PycharmProjects\VNCGrubber\venv\lib\site-packages\twisted\internet\base.py", line 1328, in mainLoop
    reactorBaseSelf.runUntilCurrent()
  File "C:\Users\User\PycharmProjects\VNCGrubber\venv\lib\site-packages\twisted\internet\base.py", line 967, in runUntilCurrent
    f(*a, **kw)
  File "C:\Users\User\PycharmProjects\VNCGrubber\venv\lib\site-packages\twisted\internet\defer.py", line 532, in addCallback
    return self.addCallbacks(callback, callbackArgs=args, callbackKeywords=kwargs)
  File "C:\Users\User\PycharmProjects\VNCGrubber\venv\lib\site-packages\twisted\internet\defer.py", line 512, in addCallbacks
    self._runCallbacks()
--- <exception caught here> ---
  File "C:\Users\User\PycharmProjects\VNCGrubber\venv\lib\site-packages\twisted\internet\defer.py", line 892, in _runCallbacks
    current.result = callback(  # type: ignore[misc]
  File "C:\Users\User\PycharmProjects\VNCGrubber\venv\lib\site-packages\vncdotool\api.py", line 83, in disconnector
    protocol.transport.loseConnection()
builtins.AttributeError: 'NoneType' object has no attribute 'transport'

Additional information This error is thrown when disconnecting from the server (when calling client.disconnect()), it is not called on every server. This error can be fixed by changing the vncdotool.api.ThreadedVNCClientProxy.disconnect method:

def disconnect(self):
     def disconnector(protocol):
         protocol.transport.loseConnection()
     reactor.callFromThread(self.factory.deferred.addCallback, disconnector)

to:

def disconnect(self):
     def disconnector(protocol):
         if protocol:
             protocol.transport.loseConnection()
     reactor.callFromThread(self.factory.deferred.addCallback, disconnector)
pmhahn commented 1 year ago

vncdotool version 1.0.0 is very old; version 1.1.0 is available since April this year; have you checked that version?

The connection handling code has also been rewritten in the current main branch; sadly that version is not yet available on PyPI. That version worked for me:

from vncdotool.api import connect
c = connect("127.0.0.1:0")
c.disconnect()

@sibson Can you please do another release to PyPI?

MrNom4ik commented 1 year ago

vncdotool version 1.0.0 is very old; version 1.1.0 is available since April this year; have you checked that version?

The connection handling code has also been rewritten in the current main branch; sadly that version is not yet available on PyPI. That version worked for me:

from vncdotool.api import connect
c = connect("127.0.0.1:0")
c.disconnect()

@sibson Can you please do another release to PyPI?

i am not using version 1.1.0 due to https://github.com/sibson/vncdotool/issues/256

pmhahn commented 1 year ago

@sibson Can you please do another release to PyPI?

i am not using version 1.1.0 due to #256

And exactly that bug is hopefully already fixed in current git, do please do a pip install git+https://github.com/sibson/vncdotool and reports your findings at #256 so we get progress there, which will then allow us to publish that version to PyPI, which then will allow you to use that version to get progress here. Thank you.