flask-uwsgi-websocket icon indicating copy to clipboard operation
flask-uwsgi-websocket copied to clipboard

uwsgi_response_write_body_do() erros

Open hackermd opened this issue 9 years ago • 2 comments

Sometimes I get the following errors:

uwsgi_response_write_body_do(): Broken pipe [core/writer.c line 419] during GET /output (127.0.0.1)

or

uwsgi_websockets_recv_pkt(): Connection reset by peer [core/websockets.c line 194] during GET /output (127.0.0.1)

or

uwsgi_response_write_body_do(): Protocol wrong type for socket [core/writer.c line 419] during GET /output (127.0.0.1)

The above listed errors seem to only occur for process that require a long time to compute. Weirdly, I get different errors when I simply re-run the same request.

This is the code (exemplified) that I'm running on server (the code itself runs without error):

from flask import Flask
from flask.ext.uwsgi_websocket import GeventWebSocket

app = Flask('myApp', static_folder=cfg.CLIENT_DIR_LOCATION, static_url_path='')
ws = GeventWebSocket(app)

@ws.route('/output')
def run_job(ws):
   while True:
        message = ws.receive()
        if message:
            send_data = json.loads(message)
            data = send_data['data']
            # Then I run some code in a loop and return the output
           for i in data:
               output = i
               ws.send(json.dumps({
                        'event': 'output',
                        'data': output
               }))

And I run the app as follows:

app.run(debug=True, port=8000, gevent=100)

How can I prevent this from happening?

hackermd avatar Jun 03 '15 11:06 hackermd

What version of uwsgi are you using?

zeekay avatar Jun 12 '15 08:06 zeekay

I'm using version 2.0.10.

I was in the meanwhile able to solve the uwsgi_response_write_body_do() problem. This was somehow related to my client side (ngWebsocket) disconnecting. Why the client disconnected is not clear to me, however.

Worth mentioning could be that I'm calling subprocess32 with Popen at # Then I run some code in a loop and return the output and it seems that the errors occur when processes take longer to compute.

hackermd avatar Jun 12 '15 08:06 hackermd