9

Getting 503 Fetch Failed in M2. I've redis and Varnish server running along with Nginx my varnishlog says

my default.vcl

 vcl 4.0;
import std;
# The minimal Varnish version is 4.0
# For SSL offloading, pass the following header in your proxy server or load balancer: 'X-Forwarded-Proto: https'
backend default {
 .host = "localhost";
 .port = "8080";
}
acl purge {
 "localhost";
}
sub vcl_recv {
 if (req.method == "PURGE") {
 if (client.ip !~ purge) {
 return (synth(405, "Method not allowed"));
 }
 if (!req.http.X-Magento-Tags-Pattern) {
 return (synth(400, "X-Magento-Tags-Pattern header required"));
 }
 ban("obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern);
 return (synth(200, "Purged"));
 }

VARNISH LOG

 * << Request >> 32838
- Begin req 32837 rxreq
- Timestamp Start: 1468597956.246653 0.000000 0.000000
- Timestamp Req: 1468597956.246653 0.000000 0.000000
- ReqStart 192.168.1.1 19182
- ReqMethod GET
- ReqURL /robots.txt
- ReqProtocol HTTP/1.1
- ReqHeader Cache-Control: no-cache
- ReqHeader Connection: Keep-Alive
- ReqHeader Pragma: no-cache
- ReqHeader Accept: */*
- ReqHeader Accept-Encoding:
- ReqHeader From: bingbot(at)microsoft.com
- ReqHeader Host: www.salon-towels.com
- ReqHeader User-Agent: Mozilla/5.0 (compatible; bingbot/2.0; +http://www
- ReqHeader X-Forwarded-For: 192.168.1.1
- VCL_call RECV
- ReqURL /robots.txt
- VCL_return hash
- ReqUnset Accept-Encoding:
- VCL_call HASH
- VCL_return lookup
- VCL_call MISS
- VCL_return fetch
- Link bereq 32839 fetch
- Timestamp Fetch: 1468597961.245436 4.998783 4.998783
- RespProtocol HTTP/1.1
- RespStatus 503
- RespReason Backend fetch failed
- RespHeader Date: 2016年7月15日 15:52:41 GMT
- RespHeader Server: Varnish
- RespHeader Content-Type: text/html; charset=utf-8
- RespHeader Retry-After: 5
- RespHeader X-Varnish: 32838
- RespHeader Age: 0
- RespHeader Via: 1.1 varnish-v4
- VCL_call DELIVER
- RespUnset Age: 0
- RespUnset Server: Varnish
- RespUnset X-Varnish: 32838
- RespUnset Via: 1.1 varnish-v4
- VCL_return deliver
- Timestamp Process: 1468597961.245516 4.998863 0.000080
- RespHeader Content-Length: 282
- Debug "RES_MODE 2"
- RespHeader Connection: keep-alive
- Timestamp Resp: 1468597961.245621 4.998968 0.000105
- ReqAcct 272 0 272 175 282 457
- End
* << Session >> 32837
- Begin sess 0 HTTP/1
- SessOpen 192.168.1.1 19182 :80 192.168.1.34 80 1468597956.246550 15
- Link req 32838 rxreq
- SessClose REM_CLOSE 5.082
asked Jul 15, 2016 at 16:13
3
  • Can you access the site at localhost:8080? Commented Jul 18, 2016 at 14:00
  • Sohaib , Did you get solution for this? Commented Nov 30, 2017 at 6:03
  • trying to connect to localhost:8080 may not tell you much as generally the first response is to forward you to the public port if the url/servername doesn't match Commented Mar 5, 2018 at 18:36

6 Answers 6

7

In Magento 2, this error is caused because the length of cache tags is more than 8192 characters. You can fix this error by increasing http_resp_hdr_len value in varnish configuration file.

I followed this tutorial https://magentip.com/magento-2-error-503-backend-fetch-failed-with-varnish-cache/ and successfully fixed that error.

Step 1: Depend on your OS, navigate to:

Ubuntu: /etc/default/varnish

CentOS 6.x: /etc/sysconfig/varnish

CentOS 7.x: /etc/varnish/varnish.params

Step 2:

Edit config file and add the following line:

-p http_resp_hdr_len=42000

For example:

DAEMON_OPTS="-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \
 -f ${VARNISH_VCL_CONF} \
 -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \
 -t ${VARNISH_TTL} \
 -p thread_pool_min=${VARNISH_MIN_THREADS} \
 -p thread_pool_max=${VARNISH_MAX_THREADS} \
 -p http_resp_hdr_len=42000 \

Save file and restart your server. The error should be gone.

answered Mar 27, 2017 at 6:25
1
  • In mac + brew, I did sudo /usr/local/sbin/varnishd -n /usr/local/var/varnish -f /usr/local/etc/varnish/default.vcl -s malloc,1G -T 127.0.0.1:2000 -a 127.0.0.1:80 -F -p workspace_backend=128k -p http_resp_size=256k -p http_resp_hdr_len=42000 And that solves the issue. As it takes over the current terminal, I did this in new tab. Commented Sep 26, 2018 at 22:21
0

If your are struggling with cached 503 pages that the problem is there is no setting default cache tag for Varnish cache.

There are might be two options to struggle with empty cache tags.

Open your varnish configuration *.vcl file and in section sub vcl_backend_response choose your option:

  1. Add disabling cache:

    if (!beresp.http.X-Magento-Tags) {
     set beresp.ttl = 0s;
     set beresp.uncacheable = true;
    }
    
  2. Add default tag store in case tags weren't passed:

    if (!beresp.http.X-Magento-Tags) {
     set beresp.http.X-Magento-Tags = "store";
    }
    

In option "1" your "wrong" cases won't be cached.

In option "2" you will be able to drop cache for 503 or other "wrong" cases.

answered Feb 28, 2018 at 20:56
0

I was moving around attributes from groups to un-assigned group in Magento 2.10, I notice I was having issue with Varnish and the error was Varnish 503 Backend Fetch Failed.

The problem was in "clean_cache_by_tags" function in Magento. I think it’s an error clearing the cache in php7 & magento2.

solution define here https://www.sohaib.com/magento-2-12-varnish-error-503-backend-fetch-failed-solved-php-7-1-nginx-varnish-5-x/

Rizwan Khan
1,9692 gold badges20 silver badges43 bronze badges
answered Jul 19, 2016 at 19:01
6
  • 1
    So what is the solution? you copied part of the answer but the critical part. Commented Jan 25, 2018 at 7:26
  • I've posted the solution today. It's a BUG and solved check my blog for answer sohaib.com/2018/01/26/… Commented Jan 27, 2018 at 4:43
  • Thank you for your reply. In my case, this happened to a freshly installed MG and the issue turned to be that the server had Varnish disabled ( which I did myself earlier) while the Mag app had that setting enabled. I made sure that Varnish is disabled everywhere and the issue was solved. This was on Cloud hosting where Varnish can be disabled/enabled on both server and application level. Commented Jan 28, 2018 at 9:03
  • 2
    @SohaibKhan your solution link is not working. Can you please share correct url. Commented Jan 31, 2018 at 3:31
  • 1
    This is the correct link: sohaib.com/… Commented Jun 6, 2018 at 9:40
0

Error is due to length of cache tags used by Magento exceed Varnish’s default of 8192 bytes. Please follow the Magento documentation to Troubleshooting 503 errors [Backend Fetch Failed errors]. https://devdocs.magento.com/guides/v2.3/config-guide/varnish/tshoot-varnish-503.html

answered Sep 27, 2019 at 8:07
0

In my situation 503 was caused by an extension I added. I've not explored the root cause but it was something to do with fetching a huge set of products on the homepage that I think was causing some sort of memory overload.

To resolve I did php bin/magento module:status to view the enabled modules. Then I ran

php bin/magento disable Vendor_Module to disable the offending module, followed by

php bin/magento setup:di:compile , then refresh the homepage

answered Apr 19, 2022 at 18:49
0

for me the issue got resolved when i disabled Magento CSP

php bin/magento module:disable Magento_Csp
answered Oct 26, 2023 at 8:59

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.