Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uwsgi IOError: write error

Tags:

nginx

uwsgi

I have a problem with my nginx+uwsgi configuration for my django app, I keep getting this errors in the uwsgi error log:

Wed Jan 13 15:26:04 2016 - uwsgi_response_writev_headers_and_body_do(): Broken pipe [core/writer.c line 296] during POST /company/get_unpaid_invoices_chart/ (86.34.48.7) IOError: write error

Wed Jan 13 15:26:20 2016 - uwsgi_response_write_headers_do(): Broken pipe [core/writer.c line 238] during GET /gestiune/print_pdf/nir/136194/ (89.122.255.186) IOError: write error

I am not getting them for all the requests but I do get a couple of them each minute. I searched for it and I understand that this happens because nginx closes the connection to uwsgi by the time uwsgi wants to write the response. This looks strange because in my nginx configuration I have this:

include uwsgi_params;

uwsgi_pass unix:/home/project/django/sbo_cloud/site.sock;

uwsgi_read_timeout 600;

uwsgi_send_timeout 600;

uwsgi_connect_timeout 60;

I am certain that none of the requests for which the error appears has exceeds the 600 seconds timeout. Any idea why this would happen?

Thanks

like image 523
Virgil Balibanu Avatar asked Jan 13 '16 13:01

Virgil Balibanu


1 Answers

The problem is that clients abort the connection and then Nginx closes the connection without telling uwsgi to abort. Then when uwsgi comes back with the result the socket is already closed. Nginx writes a 499 error in the log and uwsgi throws a IOError.

The non optimal solution is to tell Nginx not to close the socket and wait for uwsgi to come back with a response.

Put uwsgi_ignore_client_abort in your nginx.config.

location @app {     include uwsgi_params;     uwsgi_pass unix:///tmp/uwsgi.sock;      # when a client closes the connection then keep the channel to uwsgi open. Otherwise uwsgi throws an IOError     uwsgi_ignore_client_abort on; } 

It is not clear if it is possible to tell Nginx to close the uwsgi connection. There is another SO questin about this issues: (Propagate http abort/close from nginx to uwsgi / Django)

like image 120
David Dehghan Avatar answered Sep 23 '22 18:09

David Dehghan