183

I am running uwsgi in emperor mode

uwsgi --emperor /path/to/vassals/ --buffer-size=32768

and getting this error

invalid request block size: 21327 (max 4096)...skip

What to do? I also tried -b 32768.

vvvvv
  • 25,404
  • 19
  • 49
  • 81
Kartik Rokde
  • 3,633
  • 8
  • 27
  • 33
  • 3
    The buffer size is obviously still the default value (4096), make sure you're working on the right instance. You can also write "-b 32k". Also make sure this option (buffer-size) is not already set in some configuration file. – zakinster Apr 08 '13 at 11:53
  • There's no configuration file. Still not working :( – Kartik Rokde Apr 08 '13 at 12:52
  • 9
    https://uwsgi-docs.readthedocs.org/en/latest/ThingsToKnow.html you are trying to connect to a uwsgi socket using the http protocol, in addition to this the options specified to the emperor are not inherited, it is only a process manager – roberto Apr 08 '13 at 14:54
  • @zakinster For some reason the value format with `k` didn't work for me. Had to provide full number. Can't find any pointers on the formats you can use here. – famousgarkin Mar 04 '15 at 17:16

9 Answers9

261

I aslo ran into same issue while following some tutorial. The problem was that I set the option socket = 0.0.0.0:8000 instead of http = 0.0.0.0:8000. socket option intended to be used with some third-party router (nginx for instance), while when http option is set uwsgi can accept incoming HTTP requests and route them by itself.

Palasaty
  • 5,181
  • 1
  • 26
  • 22
  • 6
    I'd just like to comment on this: uwsgi has "http", "http-socket" and "socket" options. I wanted to call cgi python scripts; "socket" was the answer. – NuclearPeon May 29 '14 at 19:06
  • In Nginx configuration file we may want to use this: include /etc/nginx/uwsgi_params; uwsgi_pass django_upstream; – mennanov Feb 03 '15 at 18:04
  • 4
    It's not the correct solution. What if we want to unix sockets? – Farshid Ashouri Aug 21 '15 at 11:28
  • 3
    @Farsheed, I've just described why OP is seeing this error. How to fix it is completely up to you. It may be `socket = /tmp/myapp.sock` or `http = 0.0.0.0:8000` or whatever depending on your needs. – Palasaty Aug 24 '15 at 11:50
  • 1
    While this answer could solve the problem in some situations, I think that the correct answer in the general case is the one provided by @Farsheed below. – Augusto Destrero Nov 15 '19 at 10:44
201

The correct solution is not to switch to HTTP protocol. You just need to increase the buffer size in uWSGI settings.

buffer-size=32768

or in commandline mode:

-b 32768

Quote from official documentation:

By default uWSGI allocates a very small buffer (4096 bytes) for the headers of each request. If you start receiving “invalid request block size” in your logs, it could mean you need a bigger buffer. Increase it (up to 65535) with the buffer-size option.

If you receive ‘21573’ as the request block size in your logs, it could mean you are using the HTTP protocol to speak with an instance speaking the uwsgi protocol. Don’t do this.

From here: https://uwsgi-docs.readthedocs.io/en/latest/ThingsToKnow.html

Dmitry P.
  • 356
  • 2
  • 13
Farshid Ashouri
  • 16,143
  • 7
  • 52
  • 66
  • 2
    Sometimes you _have_ to use http protocol, since unix sockets are only available on local machine. Consider a situation when you have a number of machines and a separate balancer on top of them - you have to use `http-socket` here. – Palasaty Aug 24 '15 at 11:56
  • @Palasaty or an IP socket and `uwsgi` protocol, then you may also get the same error as OP – Andrei Oct 01 '15 at 19:39
  • 2
    @Palasaty, in any cause, fixing buffer-size will fix problem! – Farshid Ashouri Dec 01 '15 at 13:33
  • When using nginx as a reverse proxy I had to use `http-socket`. Anything else gave "502 Bad Gateway", even when the buffer size was increased. – Hubro Aug 29 '16 at 09:26
  • 1
    As for quoted documentation " If you receive ‘21573’ as the request block size in your logs, it could mean you are using the HTTP protocol to speak with an instance speaking the uwsgi protocol. Don’t do this." So is clear that the suggestion is wrong.... Also, @Kartic user has already tried to use "-b" option... – LittleEaster Jun 05 '19 at 21:45
  • @LittleEaster Actually it is one of working `workarounds`. – Farshid Ashouri Jun 06 '19 at 04:24
20

I could fix it adding --protocol=http to the uwsgi.

vvvvv
  • 25,404
  • 19
  • 49
  • 81
ajamardo
  • 589
  • 6
  • 8
14

I ran into the same issue trying to run it under nginx and was following the docs here. It is important to note that once you switch to nginx you have to make sure you are not trying to access the app on the port specified by the --socket param but rather the "listen" port in nginx.conf. Although your problem is described differently the title matches exactly the issue I had.

vvvvv
  • 25,404
  • 19
  • 49
  • 81
Paulo SantAnna
  • 1,365
  • 1
  • 10
  • 15
  • yes I ran into the same thing. in other words, i got an error when I curled the port locally, whereas I could successfully navigate to the the 'location' of my wsgi reverse-proxy as specified in my `nginx.conf', because the protocol of the wsgi server on my chosen socket was wsgi and not http – danyamachine Aug 20 '14 at 15:16
9

This error is shown when uWSGI server is using uwsgi protocol and one tries to access it via http protocol by curl or web browser directly. If you can, try configuring your uWSGI server to use http protocol, so you can access it via web browser or curl.

In case you cannot (or do not want to) change it, you can use a reverse proxy (e.g. nginx) in front of local or remote uWSGI server, see https://uwsgi-docs.readthedocs.org/en/latest/Nginx.html

If it feels like too much work, give a try to uwsgi-tools python package:

$ pip install uwsgi-tools

$ uwsgi_curl 10.0.0.1:3030

There is also a simple reverse proxy server uwsgi_proxy if you need to access your application(s) via web browser etc. See more expanded answer https://stackoverflow.com/a/32893520/179581

Andrei
  • 10,918
  • 12
  • 76
  • 110
6

As pointed out in another comment from the docs:

If you receive ‘21573’ as the request block size in your logs, it could mean you are using the HTTP protocol to speak with an instance speaking the uwsgi protocol. Don’t do this.

If you are using Nginx, this will occur if you are have this configuration (or something similarly odd):

proxy_pass http://unix:/path/to/socket.sock

this is speaking HTTP to uWSGI (which makes it grumpy). Instead, use:

uwsgi_pass unix:/path/to/socket.sock;
Demitri
  • 13,134
  • 4
  • 40
  • 41
0

man i m havin same issue; so i did it ... look using UWSGI + DJANGO + NGINX + REACT +

1 - nano /etc/uwsgi/sites/app_plataform.ini [uwsgi]

DJANGO_SETTINGS_MODULE = app_plataform.settings env = DJANGO_SETTINGS_MODULE settings.configure()

chdir = /home/app_plataform home = /root/app_plataform module = prometheus_plataform.wsgi:application

master = true processes = 33 buffer-size=32768

socket = /home/app_plataform/app_plataform.sock chmod-socket = 777 vacuum = true

2 - make a serious performance upgrade on nginx ... user www-data;

worker_processes auto; worker_processes 4; pid /run/nginx.pid; include /etc/nginx/modules-enabled/*.conf;

events { worker_connections 4092; multi_accept on; }

http { ##UPGRADE CONFIGS

client_body_buffer_size 16K; client_header_buffer_size 16k; client_max_body_size 32m; #large_client_header_buffers 2 1k;

client_body_timeout 12; client_header_timeout 12; keepalive_timeout 15; send_timeout 10; access_log off;

## # Basic Settings ##

sendfile on; tcp_nopush on; tcp_nodelay on; #keepalive_timeout 65; types_hash_max_size 2048; server_tokens off;

server_names_hash_bucket_size 64; # server_name_in_redirect off;

include /etc/nginx/mime.types; default_type application/octet-stream;

## # SSL Settings ##

ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE ssl_prefer_server_ciphers on;

## # Logging Settings ##

access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log;

## # Gzip Settings ##

gzip on; gzip_comp_level 2; gzip_min_length 1000; gzip_proxied
expired no-cache no-store private auth; gzip_types text/plain application/x-javascript text/xml text/css application/xml; gzip_vary on;

#gzip_proxied any; #gzip_comp_level 6; gzip_buffers 16 8k; gzip_http_version 1.1; #gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

## # Virtual Host Configs ##

include /etc/nginx/conf.d/.conf; include /etc/nginx/sites-enabled/; }

3 - then ... restart services or reebot server ...

systemctl restart uwsgi & systemctl restart nginx

0

for this particular error invalid request block size: 21327 (max 4096)...skip it depends on where you're running your solution either on a local machine or a remote server(AWS......).

this solution worked for me as I shrugged with this working on my local machine and as well within a docker container 1 -- change from socket = :8000 in your ini file to http= :8000

and this would work perfectly within docker as well

Muhammadyk
  • 121
  • 1
  • 7
-1

You can increase the buffer size in uWSGI settings.

The quick solution would be, Remove cookies from the browser for that URL.

Open developer tools in browser > Go to Application tab and > remove cookies associated with the URL.

hardika
  • 572
  • 5
  • 17