From 9c4cf4ada2a421c935b29cbf456fd9d7fd4697c2 Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Thu, 13 Jan 2011 12:22:22 -0600 Subject: [PATCH] Do not hang on non-ready client connection. Wait 3 seconds for the client to send something. If no data is available within 3 seconds then close the connection. It's probably a non-WebSockets client that is waiting for the server to say something first. --- websocket.py | 6 +++++- websockify | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/websocket.py b/websocket.py index d92b0ff..e8db441 100755 --- a/websocket.py +++ b/websocket.py @@ -213,7 +213,11 @@ Connection: Upgrade\r stype = "" - # Peek, but don't read the data + ready = select.select([sock], [], [], 3)[0] + if not ready: + raise self.EClose("ignoring socket not ready") + # Peek, but do not read the data so that we have a opportunity + # to SSL wrap the socket first handshake = sock.recv(1024, socket.MSG_PEEK) #self.msg("Handshake [%s]" % repr(handshake)) diff --git a/websockify b/websockify index fed4c04..e9ef5b3 100755 --- a/websockify +++ b/websockify @@ -160,7 +160,10 @@ Traffic Legend: try: self.do_proxy(client, tsock) except: - if tsock: tsock.close() + if tsock: + tsock.close() + self.vmsg("%s:%s: Target closed" %( + self.target_host, self.target_port)) if self.rec: self.rec.write("'EOF']\n") self.rec.close()