Hi,

I encountered a problem using suWSGI and uploading large files.
If file is larger than 2-5 MB I recieved Timeout reading error at 
uwsgi-body-read as below. It does not happen when unencrypted communication is 
configured between nginx and uWSGI

My workflow looks like this
HTTP_Client - > HTTP -> nginx -> suwsgi -> uWSGI -> python app

I tried it with Chrome. Edge, Firefox and curl.
I tried with various buffer-size and socket-timetout values.

Do yo have any idea what might be wrong?

Regads
Norbert

random file:
$ dd if=/dev/urandom of=/tmp/sample.txt bs=5M count=1
curl command:
curl -F "userfile=@/tmp/sample.txt" -i -X POST -H "Content-Type: 
multipart/form-data"  http://localhost

my test app source code:
http://pastebin.com/S5aX31nu



So, this is log from uWSGI:
$ uwsgi --ini uwsgi.ini
[uWSGI] getting INI configuration from uwsgi.ini
*** Starting uWSGI 2.0.14 (64bit) on [Fri Nov 11 18:02:40 2016] ***
compiled with version: 4.8.5 20150623 (Red Hat 4.8.5-4) on 11 November 2016 
16:53:45
os: Linux-3.10.0-327.10.1.el7.x86_64 #1 SMP Tue Feb 16 17:03:50 UTC 2016
nodename: ip-172-31-48-5
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /srv/upload
writing pidfile to /srv/upload/pid
detected binary path: /usr/bin/uwsgi
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
chdir() to /srv/upload
your processes number limit is 3821
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to TCP address 0.0.0.0:8003<http://0.0.0.0:8003/> fd 3
Python version: 2.7.5 (default, Sep 15 2016, 22:37:39)  [GCC 4.8.5 20150623 
(Red Hat 4.8.5-4)]
Set PythonHome to /srv/upload
*** Python threads support is disabled. You can enable it with --enable-threads 
***
Python main interpreter initialized at 0xb1c4d0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 268414 bytes (262 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0xb1c4d0 pid: 
12023 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 12023)
spawned uWSGI worker 1 (pid: 12024, cores: 1)
unable to stat() /srv/vault/reload, events will be triggered as soon as the 
file is created
[uwsgi-body-read] Timeout reading 749 bytes. Content-Length: 5243072 consumed: 
5242323 left: 749
Traceback (most recent call last):
  File "/srv/upload/upload.py", line 12, in application
    keep_blank_values=True
  File "/usr/lib64/python2.7/cgi.py", line 507, in __init__
    self.read_multi(environ, keep_blank_values, strict_parsing)
  File "/usr/lib64/python2.7/cgi.py", line 636, in read_multi
    environ, keep_blank_values, strict_parsing)
  File "/usr/lib64/python2.7/cgi.py", line 509, in __init__
    self.read_single()
  File "/usr/lib64/python2.7/cgi.py", line 646, in read_single
    self.read_lines()
  File "/usr/lib64/python2.7/cgi.py", line 668, in read_lines
    self.read_lines_to_outerboundary()
  File "/usr/lib64/python2.7/cgi.py", line 696, in read_lines_to_outerboundary
    line = self.fp.readline(1<<16)
IOError: error during readline(65536) on wsgi.input
[pid: 12024|app: 0|req: 1/1] ::1 () {38 vars in 553 bytes} [Fri Nov 11 18:02:45 
2016] POST / => generated 0 bytes in 40086 msecs (HTTP/1.1 500) 0 headers in 0 
bytes (3 switches on core 0)

This is log from nginx:
2016/11/11 16:56:46 [error] 32053#0: *1 upstream prematurely closed connection 
while reading response header from upstream, client: x.x.x.x, server: _, 
request: "POST / HTTP/1.1", upstream: 
"suwsgi://127.0.0.1:8003<http://127.0.0.1:8003/>", host: "107.20.110.245", 
referrer: "http://107.20.110.245/";

this is my uwsgi.ini:
[uwsgi]
suwsgi-socket = 
0.0.0.0:8003<http://0.0.0.0:8003/>,/srv/upload/uwsgi.cert,/srv/upload/uwsgi.key
pidfile = /srv/upload/pid
enable-threads = false
wsgi-file = /srv/upload/upload.py
chdir = /srv/upload
virtualenv = /srv/upload
socket-timeout = 40
buffer-size = 66384

this is my nginx conf:

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {    worker_connections 8; }

http {
client_max_body_size    0;   # I expect large files to be uploaded. like 
hundreds of megabytes
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;
    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    upstream uwsgi-host {        server localhost:8003;    }
    server {
        listen       80 default_server;   listen       [::]:80 default_server;
        server_name  _;  root         /usr/share/nginx/html;

        location / {
            uwsgi_pass_header       X_FORWARDED_PROTOCOL;
            uwsgi_pass              suwsgi://uwsgi-host;
            uwsgi_param UWSGI_SCHEME        http;
            uwsgi_param QUERY_STRING        $query_string;
            uwsgi_param REQUEST_METHOD      $request_method;
            uwsgi_param CONTENT_TYPE        $content_type;
            uwsgi_param CONTENT_LENGTH      $content_length;
            uwsgi_param REQUEST_URI         $request_uri;
            uwsgi_param PATH_INFO           $document_uri;
            uwsgi_param DOCUMENT_ROOT       $document_root;
            uwsgi_param SERVER_PROTOCOL     $server_protocol;
            uwsgi_param REMOTE_ADDR         $remote_addr;
            uwsgi_param REMOTE_PORT         $remote_port;
            uwsgi_param SERVER_PORT         $server_port;
            uwsgi_param SERVER_NAME         $server_name;
            uwsgi_read_timeout              600s;
            uwsgi_send_timeout              600s;
            send_timeout                    600s;
        }
    }
}

_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi

Reply via email to