6

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: Fri, 15 Jul 2016 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
  • Can you access the site at localhost:8080? – Aric Watson Jul 18 '16 at 14:00
  • Sohaib , Did you get solution for this? – Camit1dk Nov 30 '17 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 – Scott Mar 5 '18 at 18:36
4

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://magentoexplorer.com/magento-2-error-503-backend-fetch-failed-how-to-fix 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.

  • 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. – Asrar Sep 26 '18 at 22:21
1

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/

  • 1
    So what is the solution? you copied part of the answer but the critical part. – Mohammed Joraid Jan 25 '18 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/… – Sohaib Khan Jan 27 '18 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. – Mohammed Joraid Jan 28 '18 at 9:03
  • 1
    @SohaibKhan your solution link is not working. Can you please share correct url. – Palanikumar Jan 31 '18 at 3:31
  • This is the correct link: sohaib.com/… – Densen Jun 6 '18 at 9:40
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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.