aboutsummaryrefslogtreecommitdiffstats
path: root/netlib/tcp.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@corte.si>2013-07-28 14:55:40 -0700
committerAldo Cortesi <aldo@corte.si>2013-07-28 14:55:40 -0700
commit6709253629ce5eb3efbc7b505ceb6e88eb20c441 (patch)
treebb95d6117617c482e32da72e9797c9e67f970b27 /netlib/tcp.py
parentef2f099c08b738699e577653b0474895cd10d463 (diff)
parent68e2e782b0afdc03844b107c28627391c51dd036 (diff)
downloadmitmproxy-6709253629ce5eb3efbc7b505ceb6e88eb20c441.tar.gz
mitmproxy-6709253629ce5eb3efbc7b505ceb6e88eb20c441.tar.bz2
mitmproxy-6709253629ce5eb3efbc7b505ceb6e88eb20c441.zip
Merge pull request #16 from mitmproxy/fix_socket_buffer
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 b5e9e2c4..69ad2da5 100644
--- a/netlib/tcp.py
+++ b/netlib/tcp.py
@@ -233,11 +233,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:
@@ -331,10 +335,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()