Issue #53 new

If the application returns a generator, we need to iterate over it

Anonymous created an issue

This is particularly bad when using Flask, because Flask seems to always return a generator. Since we don't iterate over it, the code to actually handle the websocket request never gets called.

The issue is at https://bitbucket.org/Jeffrey/gevent-websocket/src/ce69815583e80a2c98eab9badcafe714749cb2e5/geventwebsocket/handler.py?at=default#cl-52 ; if the result of that call is a generator, we may want to list() it or something similar.

Comments (3)

  1. davidkhess

    Here's the basic setup that causes the issue (not tested code, but this basic pattern):

    from geventwebsocket.server import WebSocketServer
    from werkzeug.debug import DebuggedApplication
    from werkzeug.serving import run_with_reloader
    from app import app
    
    server = WebSocketServer(
        (app.config["HOST"], app.config["PORT"]),
        DebuggedApplication(app)
    )
    
    def run():
        server.serve_forever()
    
    run_with_reloader(run)
    

    DebuggedApplication is what causes Flask to print out a nice traceback and interactive debugger when an exception is thrown. run_with_reloader is what reloads the application when a source file changes on disk. The issue is that DebuggedApplication returns a generator that doesn't write to the web socket until it is iterated over (which never happens).

    One way to fix it would likely be to change the referenced line from:

                self.application(self.environ, lambda s, h: [])
    

    to

                list(self.application(self.environ, lambda s, h: []))
    
  2. Log in to comment