diff options
author | Aldo Cortesi <aldo@corte.si> | 2013-07-28 14:55:40 -0700 |
---|---|---|
committer | Aldo Cortesi <aldo@corte.si> | 2013-07-28 14:55:40 -0700 |
commit | 6709253629ce5eb3efbc7b505ceb6e88eb20c441 (patch) | |
tree | bb95d6117617c482e32da72e9797c9e67f970b27 /netlib/tcp.py | |
parent | ef2f099c08b738699e577653b0474895cd10d463 (diff) | |
parent | 68e2e782b0afdc03844b107c28627391c51dd036 (diff) | |
download | mitmproxy-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.py | 15 |
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() |