Exceptions thrown on client disconnect

Miguel Turner avatarMiguel Turner created an issue

I have a webapp that tries to maintain a websocket connection, and which reconnects on page refreshes. Though the webapp works fine, I began to notice an exception when the server tries to handle the disconnect of a websocket.

This is the first exception:

Traceback (most recent call last):
  File "./gevent/pywsgi.py", line 508, in handle_one_response
    self.run_application()
  File "./geventwebsocket/handler.py", line 76, in run_application
    self.run_websocket()
  File "./geventwebsocket/handler.py", line 52, in run_websocket
    self.application(self.environ, lambda s, h: [])
  File "./beaker/middleware.py", line 155, in __call__
    return self.wrap_app(environ, session_start_response)
  File "./bottle.py", line 978, in __call__
    return self.wsgi(environ, start_response)
  File "./bottle.py", line 973, in wsgi
    start_response('500 INTERNAL SERVER ERROR', headers, sys.exc_info())
  File "./beaker/middleware.py", line 154, in session_start_response
    return start_response(status, headers, exc_info)
TypeError: <lambda>() takes exactly 2 arguments (3 given)

This is raised because the lambda used as the start_response callback in WebSocketHandler.run_websocket does not accept the exc_info argument that can sometimes be passed.

To fix it I just added another argument to the lambda. After that I was getting another exception:

Traceback (most recent call last):
  File "./gevent/pywsgi.py", line 508, in handle_one_response
    self.run_application()
  File "./geventwebsocket/handler.py", line 76, in run_application
    self.run_websocket()
  File "./geventwebsocket/handler.py", line 54, in run_websocket
    del self.server.clients[self.client_address]
KeyError: ('127.0.0.1', 41740)

I fixed this for myself by just ignoring the KeyError, and left it at that since my goal was only to clean up my logs a bit. Another solution might be more appropriate.

Comments (0)

  1. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.