3

I'm running an Autobahn WS server and am connecting to it from a client using the Python websocket-client (https://pypi.python.org/pypi/websocket-client/).

My client code is pretty simple :-

from websocket import create_connection

# WS_URL is a valid endpoint
ws = None
try:
    ws = create_connection(WS_URL)
except:
    print 'Could not connect to websocket server ...'

sample_message = "Hello world"
while True:
    if ws is not None:
        ws.send(sample_message)

This works fine for a while but then I see the error :-

error: [Errno 104] Connection reset by peer

Searching around, it seems related to a timeout error of some kind. Can anyone suggest how to fix this ?

UPDATE

Just to confirm the server side, the WS server is simply using the stock "broadcast" example from the Autobahn docs - https://github.com/tavendo/AutobahnPython/blob/master/examples/websocket/broadcast/server.py. So messages received from a client are just echoed back out to all connected clients.

UPDATE2

Thanks for the debug tip. I ran this and, when the error occurred, this is the output from the debug trace :-

2013-10-16 12:47:47+0000 [BroadcastServerProtocol,0,172.20.12.9]  WebSocketProtocol.onClose:
    wasClean=False
    code=1006
    reason=connection was closed uncleanly (peer dropped the TCP connection without previous WebSocket closing handshake)
    self.closedByMe=False
    self.failedByMe=False
    self.droppedByMe=False
    self.wasClean=False
    self.wasNotCleanReason=peer dropped the TCP connection without previous WebSocket closing handshake
    self.localCloseCode=None
    self.localCloseReason=None
    self.remoteCloseCode=None
    self.remoteCloseReason=None

Why was the connection dropped ? The error can be reproduced and occurs after approx. the same time each run (~ 5 hours).

bzo
  • 1,532
  • 7
  • 27
  • 40
  • It simply means that the other end closed its connection. – Some programmer dude Oct 15 '13 at 14:09
  • There's no way to answer this question without knowing what happens on server side. – Max Oct 15 '13 at 14:14
  • Try running the server `python server.py debug` .. and check what the server log output hints. It'll tell you the reason it closes the connection. – oberstet Oct 15 '13 at 15:59
  • Btw: any reason you are not using Autobahn for client as well? – oberstet Oct 15 '13 at 15:59
  • Thank. I added an update to the main question containing the debug output when the error occurred. Why would the connection drop ? Regarding the client, no reason really - the client was developed by another team who happened to use that library. – bzo Oct 16 '13 at 13:20
  • oberstet - are you able to offer some advice as to why the server drops its connection ? I've done a few runs and the error is always the same (peer dropped the TCP connection without previous WebSocket closing handshake). Is there any way of defensively coding against this in the server ? I notice there's a reasonably high number of messages (~10/s) being sent to the server but that shouldn't cause the crash (?). Thanks again for any pointers to the problem. – bzo Oct 21 '13 at 12:05
  • Your client is only sending but not receiving - could it be that server's sending buffer is simply overflowing and it's dropping the connection? Either way, please post your server-side logs, it's where the issue is. – Lav Feb 26 '16 at 12:00

0 Answers0