attempt to fix 'half-duplex' TCP close sequence

This commit is contained in:
Maximilian Hils 2013-06-17 17:03:17 +02:00
parent 73f8a1e2e0
commit 68e2e782b0
1 changed files with 12 additions and 3 deletions

View File

@ -230,11 +230,15 @@ class TCPClient:
if self.ssl_established: if self.ssl_established:
self.connection.shutdown() self.connection.shutdown()
else: else:
self.connection.shutdown(socket.SHUT_RDWR) self.connection.shutdown(socket.SHUT_WR)
self.connection.close() #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): except (socket.error, SSL.Error):
# Socket probably already closed # Socket probably already closed
pass pass
self.connection.close()
class BaseHandler: class BaseHandler:
@ -328,10 +332,15 @@ class BaseHandler:
if self.ssl_established: if self.ssl_established:
self.connection.shutdown() self.connection.shutdown()
else: 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): except (socket.error, SSL.Error):
# Socket probably already closed # Socket probably already closed
pass pass
self.connection.close() self.connection.close()