From df3d2d70edaca439fc5eff769e51b304954d4143 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sun, 28 Jul 2013 18:05:04 +1200 Subject: [PATCH] Terminate can be called on an unconnected server connection. --- libmproxy/proxy.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py index 79025a348..df810da5b 100644 --- a/libmproxy/proxy.py +++ b/libmproxy/proxy.py @@ -82,14 +82,15 @@ class ServerConnection(tcp.TCPClient): self.wfile.flush() def terminate(self): - try: - self.wfile.flush() - except IOError: # pragma: no cover - pass - try: - self.connection.close() - except IOError: - pass + if self.connection: + try: + self.wfile.flush() + except IOError: # pragma: no cover + pass + try: + self.connection.close() + except IOError: + pass