unbit / uwsgi

uWSGI application server container
http://projects.unbit.it/uwsgi
Other
3.46k stars 692 forks source link

What does it means: hr_instance_read(): Connection reset by peer [plugins/http/http.c line 647] ? #1831

Open Sklavit opened 6 years ago

Sklavit commented 6 years ago

Running uwsgi (2.0.15) service + https://www.lighttpd.net/

Have the following line in logs:

[uwsgi-http key:*server-name* client_addr: *some_ip* client_port: *some_port*] hr_instance_read(): Connection reset by peer [plugins/http/http.c line 647]

What it may be?

jacopofar commented 6 years ago

Same here, it happens often and quite randomly.

The log says:

[uwsgi-http key: localhost:8080 client_addr: 127.0.0.1 client_port: 21472] hr_instance_read(): Connection reset by peer [plugins/http/http.c line 647]
invalid request block size: 4447 (max 4096)...skip

the exact meaning of the error is quite opaque for me, but following these suggestion I found that it goes away by adding buffer-size=32768

Still, I don't understand why it happens randomly and which buffer size should I use.

jacopofar commented 6 years ago

I found out what it is. It is the maximum size of all headers, both names, whitespaces and contents, for a single HTTP request. It was tricky to spot the problem because Chrome shows "provisional headers" in the developer tools and exports only them when copying to cURL but is actually sending more in the actual HTTP request, which are still visible in chrome://net-internals/#events or using a packet sniffer.

The 4KB default limit seems not far from other servers, but maybe the documentation is a bit opaque on that.

dimaqq commented 2 years ago

I think we've been hit by this issue as well, after a diligent do-gooder added uwsgi to our stack and some valid request suddenly became too large 😭

dimaqq commented 2 years ago

Here's a summary of what to expect from UWSGI with default settings:

Weirdly the thresholds are not what the docs say, for example, one of the thresholds is 2010 bytes for the total request header size or 1884 bytes for first line or 1869 byte for the url path, but not 4K as the documentation states.

If you bump buffer-size to 64K-1 (the max according to the docs), then the max request header size becomes 30681 bytes.

I would conclude that max request header size is buffer-size / 2 - C.

vsalvino commented 1 year ago

I was seeing this issue, particularly with LinkedInBot user agent when performing GETs on pages that normally work fine, but throw this error when fetched by LinkedIn for their post previews.

Doubling buffer-size from 4096 to 8192 fixed the issue!

According to this answer (and I also checked the docs for Apache and NGINX), 8 KB seems to be the most common default, hence why those servers were not exhibiting the problem. https://stackoverflow.com/a/8623061