william-os4y / fapws3

Fast Asynchronous Python Web Server (based on libev)
GNU General Public License v2.0
341 stars 38 forks source link

FAPWS3 fails to report proper status when using yielded results #8

Closed yaniv-aknin closed 14 years ago

yaniv-aknin commented 14 years ago

While writing a WSGI reliability benchmark suite, I ran into what seems to be an issue with FAPWS3. In my test, FAPWS3 fails to report 404 Not Found if the content is yielded rather than return.

See this example code, tested against version 0.4 dev: def application(environ, start_response): status = '404 Not Found' output = 'Pong!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]

    start_response(status, response_headers)
    # return [output] # <- works OK
    yield output # <- does not convey 404 status to client

import fapws._evwsgi as evwsgi
from fapws import base

evwsgi.start("0.0.0.0", 8080)
evwsgi.set_base_module(base)
evwsgi.wsgi_cb(("/", application))
evwsgi.set_debug(0)
evwsgi.run()
william-os4y commented 14 years ago

Indeed, this is not working like it should be. In case of Yield, the Call method on line 634 does not execute the procedure, but return a generator object. As for each generator object, the real execution is triggered by the next() method. This explains why the call of start_response is not triggered by the line 634.

I Think the line 634 must be adapted to perform a call/or a "next" depending on the type of procedure. But then we have to store the generator object somewhere and call it until it return a "stopiretation".

This is something I have to check before implementation.

W.

william-os4y commented 14 years ago

Done ;-)

Regression tests are still to be performed on bigger scale, but the last commit fix this bug: http://github.com/william-os4y/fapws3/commit/79005b48a8e92e3efff9b9680a758593779ffbbf

I've just implemented the design reported 3 days ago ;-)

Thanks

W.