Search code examples
varnishvarnish-vclvarnish-4

Varnish 4.1 - Call a restart according to the backend response


Prior to Varnish 4, One could call a restart from vcl_fetch to start another flow reaching vcl_recv.

In version 4, logic was separated to client and backend, I need to be able to call a restart according to the backend response. One direction I thought might be possible is using vcl_synth as a middleware between backend and client but the backend can't send a specific error code or msg only standard 503 error.

Any ideas?


Solution

  • You cannot restart a request during vcl_backend_* in Varnish 4.x.

    You could return (abandon) during vcl_backend_* and then restart the request in vcl_synth if resp.status == 503, but you cannot transport any information from vcl_backend_* to vcl_synth in order to implement a smarter conditional.

    As an alternative, you could execute the restart during vcl_deliver based on whatever was returned by the backend side.