wangshen2014 / pywebsocket

Automatically exported from code.google.com/p/pywebsocket
0 stars 0 forks source link

recieve_message() doesn't return on client disconnect #111

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I am running in to a problem where my client disconnects without a sending a 
closing handshake, causing the request.ws_stream.receive_message() call in my 
handler to never return.  It appears from the example handlers and the code for 
pywebsocket, that it should return None, but that never happens.  If you have 
multiple clients do this, the server will have a bunch of threads blocked on 
the receive_message() call.

I was able to reproduce this with Chrome 14.0.835.186 and also with the 
echo_client.py example, by removing the call to send a closing handshake in at 
the end of run() in EchoClient.

Original issue reported on code.google.com by dunca...@gmail.com on 23 Sep 2011 at 3:22

GoogleCodeExporter commented 9 years ago
receive_message returns None only when closing handshake was successful. Any 
other abnormal closures result in exception. E.g. in the case you mentioned to 
reproduce this it's actually raising ConnectionTerminatedException.

Original comment by tyoshino@chromium.org on 7 Dec 2011 at 4:49

GoogleCodeExporter commented 9 years ago
I am using version 0.6b5 and no exception is thrown on the handler thread.  Is 
the exception getting thrown on the main thread?  Were the exceptions added in 
one of the later versions?

I need receive_message() to return either with None or an exception when the 
client disconnects, regardless of if it was with a closing handshake or 
abnormal.

Original comment by dunca...@gmail.com on 7 Dec 2011 at 3:21

GoogleCodeExporter commented 9 years ago
I checked that by enclosing while loop in example/echo_wsh.py with try-except. 
I.e. handler thread.

It works with 0.6b5 release.

import msgutil
...
    try:
        while True:
            line = request.ws_stream.receive_message()
            if line is None:
                # Successful closing handshake
            # Normal processing
    except msgutil.ConnectionTerminatedException, e:
        # Connection closed unexpectedly

Original comment by tyoshino@chromium.org on 8 Dec 2011 at 2:42

GoogleCodeExporter commented 9 years ago
You are correct, the exception is being thrown.  Looks like without the 
try/catch block, the exception is silently thrown, as there is no output to the 
console.

Looks like there isn't a problem with recieve_message(), thanks for all your 
help.  You can close this issue.

Original comment by dunca...@gmail.com on 8 Dec 2011 at 3:12

GoogleCodeExporter commented 9 years ago
OK. We'll fix pydoc for receive_message method to list Exceptions it throws and 
explain them. Thanks.

Original comment by tyoshino@chromium.org on 12 Dec 2011 at 5:08