Opened 8 years ago

Closed 8 years ago

#3155 defect closed duplicate (duplicate)

Invoking loseConnection in established SSHSession raises AttributeError

Reported by: jkk Owned by: jkk
Priority: normal Milestone:
Component: conch Keywords:
Cc: therve Branch:
Author: Launchpad Bug:


Consider example:

Index: doc/conch/examples/
--- doc/conch/examples/       (revision 23176)
+++ doc/conch/examples/       (working copy)
@@ -71,7 +71,7 @@

     def execCommand(self, proto, cmd):
-        raise Exception("no executing commands")
+        proto.connectionLost()

     def openShell(self, trans):
         ep = EchoProtocol()

When client is trying to execute a command, server gets AttributError exception:

2008-04-03 09:04:12+0100 [SSHChannel session (0) on SSHService ssh-connection on SSHServerTransport,0,] executing command "haha"
2008-04-03 09:04:12+0100 [SSHChannel session (0) on SSHService ssh-connection on SSHServerTransport,0,] Unhandled Error
File "/home/jkk/Twisted/twisted/conch/ssh/", line 137, in requestReceived
 return f(data)
--- <exception caught here> ---
File "/home/jkk/Twisted-jkk/twisted/conch/ssh/", line 68, in request_exec
 self.session.execCommand(pp, f)
File "doc/conch/examples/", line 74, in execCommand
File "/home/jkk/Twisted-jkk/twisted/conch/ssh/", line 194, in connectionLost
File "/home/jkk/Twisted-jkk/twisted/conch/ssh/", line 131, in loseConnection
exceptions.AttributeError: 'NoneType' object has no attribute 'loseConnection'

On every new session request (exec command, shell etc.) self.client is initialized do SSHSessionProcessProtocol which has transport attribute set to None. Fix is then obvious:

Index: twisted/conch/ssh/
--- twisted/conch/ssh/        (revision 23176)
+++ twisted/conch/ssh/        (working copy)
@@ -128,7 +128,8 @@

     def loseConnection(self):
         if self.client:
-            self.client.transport.loseConnection()
+            if self.client.transport:
+                self.client.transport.loseConnection()

 class _ProtocolWrapper(protocol.ProcessProtocol):

Conch tests are fine with the change.

Change History (5)

comment:1 Changed 8 years ago by jml

I can confirm this bug. We work around it because we have our SSHSession subclass.

Sorry for not filing earlier.

comment:2 Changed 8 years ago by therve

  • Cc therve added
  • Keywords review removed
  • Owner changed from z3p to jkk

Are you willing to add tests for that?

comment:3 Changed 8 years ago by jkk

Sure, I'll see what can I do.

comment:4 Changed 8 years ago by jkk

This ticket duplicates #2754.

comment:5 Changed 8 years ago by exarkun

  • Resolution set to duplicate
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.