aboutsummaryrefslogtreecommitdiffstats
path: root/netlib/tcp.py
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2013-06-17 17:03:17 +0200
committerMaximilian Hils <git@maximilianhils.com>2013-06-17 17:03:17 +0200
commit68e2e782b0afdc03844b107c28627391c51dd036 (patch)
treeb71c14643b926fc3e29da44710bd04fbbccef09f /netlib/tcp.py
parent73f8a1e2e0006c2a37ae6264afe70a8207ffbb54 (diff)
downloadmitmproxy-68e2e782b0afdc03844b107c28627391c51dd036.tar.gz
mitmproxy-68e2e782b0afdc03844b107c28627391c51dd036.tar.bz2
mitmproxy-68e2e782b0afdc03844b107c28627391c51dd036.zip
attempt to fix 'half-duplex' TCP close sequence
Diffstat (limited to 'netlib/tcp.py')
-rw-r--r--netlib/tcp.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/netlib/tcp.py b/netlib/tcp.py
index 47953724..e37cb707 100644
--- a/netlib/tcp.py
+++ b/netlib/tcp.py
@@ -230,11 +230,15 @@ class TCPClient:
if self.ssl_established:
self.connection.shutdown()
else:
- self.connection.shutdown(socket.SHUT_RDWR)
- self.connection.close()
+ self.connection.shutdown(socket.SHUT_WR)
+ #Section 4.2.2.13 of RFC 1122 tells us that a close() with any pending readable data could lead to an immediate RST being sent.
+ #http://ia600609.us.archive.org/22/items/TheUltimateSo_lingerPageOrWhyIsMyTcpNotReliable/the-ultimate-so_linger-page-or-why-is-my-tcp-not-reliable.html
+ while self.connection.recv(4096):
+ pass
except (socket.error, SSL.Error):
# Socket probably already closed
pass
+ self.connection.close()
class BaseHandler:
@@ -328,10 +332,15 @@ class BaseHandler:
if self.ssl_established:
self.connection.shutdown()
else:
- self.connection.shutdown(socket.SHUT_RDWR)
+ self.connection.shutdown(socket.SHUT_WR)
+ #Section 4.2.2.13 of RFC 1122 tells us that a close() with any pending readable data could lead to an immediate RST being sent.
+ #http://ia600609.us.archive.org/22/items/TheUltimateSo_lingerPageOrWhyIsMyTcpNotReliable/the-ultimate-so_linger-page-or-why-is-my-tcp-not-reliable.html
+ while self.connection.recv(4096):
+ pass
except (socket.error, SSL.Error):
# Socket probably already closed
pass
+
self.connection.close()