Ok, my solution is to re-write the connect function like this. Any issues with this approach?
def connect(options, userAuthObject): d_connect = Deferred() d_authorized = Deferred() factory = SFTPClientFactory(d_connect, options, userAuthObject) def _connect_failed(*args, **kwargs): d_authorized.errback(args[0]) def _connected(*args, **kwargs): # Reset the factory's deferred factory.d = d_authorized d_connect.addErrback(_connect_failed).addCallback(_connected) reactor.connectTCP(options["host"], options["port"], factory) return d_authorized.addCallback(lambda ignore: factory) On Sun, Nov 29, 2020 at 9:41 AM Robert DiFalco <robert.difa...@gmail.com> wrote: > I'm continuing to wrestle with conch, this time around authentication and > notifying deferred of auth failure. > > It seems like the SSH factory has a deferred to be notified of auth > failures here: > > https://github.com/twisted/twisted/blob/trunk/src/twisted/conch/client/direct.py#L61-L66 > > Unfortunately, this deferred is cleared because prior to auth, it > receives this on successful connect: > > https://github.com/twisted/twisted/blob/trunk/src/twisted/conch/client/direct.py#L83-L88 > > As you can see this clears the deferred so it is no longer available to > get an errback. This also prevents the SSHClientTransport from getting a > sendDisconnect. > > To try it change the user to something invalid here: > https://gist.github.com/radifalco/5a5cca4bf8d49d5c61113e36f9be7553#file-sftp-py-L328 > > This will never get a callback to errback. > > I guess I would have expected this to get the error but it actually > succeeds with None. As a result there is no deferred to get the auth > failure and my app waits forever for a notification. > > There is one ting I *think* I know how to do, add a timeout with a > callback later on the sftpClient deferred. But that seems lame. What I'd > like to do is to get this ConchError as it has the actual reason for the > connection failure. Thoughts? > > > https://github.com/twisted/twisted/blob/trunk/src/twisted/conch/client/direct.py#L61-L66 > >
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python