Ticket #3155 defect closed 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: |
Description
Consider example:
Index: doc/conch/examples/sshsimpleserver.py
===================================================================
--- doc/conch/examples/sshsimpleserver.py (revision 23176)
+++ doc/conch/examples/sshsimpleserver.py (working copy)
@@ -71,7 +71,7 @@
pass
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,127.0.0.1] executing command "haha" 2008-04-03 09:04:12+0100 [SSHChannel session (0) on SSHService ssh-connection on SSHServerTransport,0,127.0.0.1] Unhandled Error (...) File "/home/jkk/Twisted/twisted/conch/ssh/channel.py", line 137, in requestReceived return f(data) --- <exception caught here> --- File "/home/jkk/Twisted-jkk/twisted/conch/ssh/session.py", line 68, in request_exec self.session.execCommand(pp, f) File "doc/conch/examples/sshsimpleserver.py", line 74, in execCommand proto.connectionLost() File "/home/jkk/Twisted-jkk/twisted/conch/ssh/session.py", line 194, in connectionLost self.session.loseConnection() File "/home/jkk/Twisted-jkk/twisted/conch/ssh/session.py", line 131, in loseConnection self.client.transport.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/session.py
===================================================================
--- twisted/conch/ssh/session.py (revision 23176)
+++ twisted/conch/ssh/session.py (working copy)
@@ -128,7 +128,8 @@
def loseConnection(self):
if self.client:
- self.client.transport.loseConnection()
+ if self.client.transport:
+ self.client.transport.loseConnection()
channel.SSHChannel.loseConnection(self)
class _ProtocolWrapper(protocol.ProcessProtocol):
Conch tests are fine with the change.
Change History
Note: See
TracTickets for help on using
tickets.
