Varnish Backend fetch failed Too many headers

This article describes particular case of Varnish error Backend fetch failed Too many headers. This error happens when there are too many headers being sent to backend server. Here is how you can troubleshoot and fix this error.

First, open the SSH session for your server with Varnish. Then run varnishlog in order to make recordings of backend requests to a text file:

Deactivate your Jetpack and activate it back again. You will see the error in the browser:

Take note of XID value in the response. It is Varnish transaction ID.

Cancel out from varnishlog command by typing Ctrl + C in SSH. Open the bereq.log file and search for the XID number in error response.

You will find the backend request information includes something like this:

This is pretty much self-explanatory. There are too many headers being sent to backend server while activating JetPack.

According to Varnish 4 documentation, there is http_max_hdr parameter, which is:

Maximum number of HTTP header lines we allow in {req|resp|bereq|beresp}.http (obj.http is autosized to the exact number of headers). Cheap, ~20 bytes, in terms of workspace memory.

The default value for the parameter is 64.

Solution

The solution to the issue is to increase the number of headers that Varnish will accept. This is done by tuning the http_max_hdr parameter from the default 64 to 96.

We have to adjust Varnish configuration for this. It’s located in either /etc/varnish/varnish.params, /etc/sysconfig/default or /etc/default/varnish depending on your Linux OS.
You need to find DAEMON_OPTS setting which controls Varnish startup parameters and add parameter for the maximum number of HTTP headers.

Example, before:

After:

Good luck!

Want me to do this for you? Drop me a line: itgalaxyzzz {at} gmail [dot] com