vcl_synth

Madhusudan Ramanna m.ramanna at ymail.com
Fri Sep 26 20:17:54 CEST 2014


To answer my own question,

I got this to work by using valid http codes in synth() call. 

>>>>>>>>>>

sub vcl_recv {

  if (req.url ~ "^/ping") {
    return (synth(200, "OK"));
  }

}

sub vcl_synth {

  if (resp.status == 200) {
    if (req.url ~ "^/ping") {
      synthetic("pong");
    }
    set resp.http.Content-Type = "text/plain; charset=utf-8";
    return (deliver);
  }

}

<<<<<<<<<<<<

No more calls to backend and varnish returns the synthetic response right away.

thanks,
Madhu

ps: please pardon typos in code if any


On Tuesday, September 9, 2014 9:38 PM, Madhusudan Ramanna <m.ramanna at ymail.com> wrote:
 


Hello, 

We're using 3.0.5 in production and currently testing 4.0.1. 

We have some urls for which we always construct synthetic responses. (/ping response pong)

In 4.x vcl,  I'm matching against the req url and returning synth with appropriate error code.

>>>>>>>>>>>>>>>

sub vcl_recv {
  if (req.url ~ "^/ping") {
    return (synth(1002, "OK"));
  }


sub vcl_synth {

  if (resp.status == 1002) {
    set resp.status = 200;
    set resp.http.Content-Type = "text/plain; charset=utf-8";
    synthetic("pong");
    return (deliver);
  }

}
<<<<<<<<<<<<<<<<<

However, when the backend is down, varnish does not return the synthetic response


< HTTP/1.1 503 OK
< Date: Wed, 10 Sep 2014 04:31:40 GMT
< Server: Varnish
< X-Varnish: 35
< Content-Length: 0
< Connection: keep-alive

Here is the varnishlog

-   ReqHeader      Host: localhost:6081
-   ReqHeader      Accept: */*
-   ReqHeader      X-Forwarded-For: 127.0.0.1
-   VCL_call       RECV
-   Debug          "VCL_error(1002, OK)"
-   VCL_return     synth
-   VCL_call       HASH
-   VCL_return     lookup
-   Timestamp      Process: 1410309978.983313 0.000075 0.000075
-   RespHeader     Date: Wed, 10 Sep 2014 00:46:18 GMT
-   RespHeader     Server: Varnish
-   RespHeader     X-Varnish: 32797
-   RespProtocol   HTTP/1.1
-   RespStatus     503
-   RespReason     Service Unavailable
-   RespReason     OK
-   VCL_call       SYNTH
-   VCL_return     deliver
-   RespHeader     Content-Length: 0


Not sure why the thread would call HASH. I would expect varnish to deliver the response after the vcl_synth call ?

Is this the expected behavior ? How can I fix this to return synthetic response without regard for the health of the backend

appreciate your response !

thank you,

Madhu

ps: Also looking forward to 4.x version of Varnish book 



_______________________________________________
varnish-misc mailing list
varnish-misc at varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20140926/5b96cc5d/attachment.html>


More information about the varnish-misc mailing list