On our site, we have "varnish_cache_clear" set to 0 so that the varnish cache is not automatically cleared on every node update. However, there is a bug in the code where the homepage is still cleared on every node update.

On node update, the clear() function in varnish.cache.inc is called with parameters (NULL, FALSE).

The "if" statement on line 42 fails correctly b/c "varnish_cache_clear" is set to 0:
if (empty($cid) && variable_get('varnish_cache_clear', 1)) {

Thus, the control is passed down to the else statement:

      if ($wildcard) {
        ...
      }
      elseif (is_array($cid)) {
        varnish_expire_cache($cid);
      }
      else {
        varnish_expire_cache(array($cid));
      }

Since $wildcard is FALSE, and $cid is NULL, we hit the final "else" statement, where the null $cid is put into an array and passed to varnish_expire_cache(). varnish_expire_cache() converts this to "^/$", which clears the home page from varnish.

As for a solution, perhaps we can change that final "else" into "elseif (isset($cid))". Not sure if this is inconsistent with line 42, though, which checks on $cid being empty instead of non-null. However, I dont believe we can change this final "else" into "elseif (!empty($cid)) because then it might not be possible to clear the homepage when actually desired.

Comments

aklump’s picture

+1 on this.

I too am seeing this issue in 7.x-1.0-beta2. we're getting something like the following in our ban.list (domain has been changed). We have a pretty active website with node updates many times a minute, so this means the homepage essential never gets served by varnish.

1389216836.626254    70   req.http.host ~ www.website-changed.com && req.url ~ ^/$
1389216829.311218     8G  req.http.host ~ www.website-changed.com && req.url ~ ^/$
1389216817.784382    50G  req.http.host ~ www.website-changed.com && req.url ~ ^/$
1389216817.779401     0G  req.http.host ~ www.website-changed.com && req.url ~ ^/$
1389216816.331035     0   req.http.host ~ default && req.url ~ ^/$
1389216816.318501     0   req.http.host ~ default && req.url ~ /
1389216814.537017     4G  req.http.host ~ www.website-changed.com && req.url ~ ^/$
1389216812.602830     1G  req.http.host ~ www.website-changed.com && req.url ~ ^/$
1389216810.404654     4G  req.http.host ~ default && req.url ~ ^/$
1389216808.246533     1G  req.http.host ~ default && req.url ~ ^/$

Our settings:

varnish_flush_cron: "0"
varnish_version: "3"
varnish_socket_timeout: 3600
varnish_cache_clear: "1"
varnish_bantype: "0"
mgifford’s picture

Sadly beta2 is 11 months old. Recommendation of best practice by developers seems to be to use the latest dev release.

MiSc’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

Closing issues that had no activity the latest year, please re-open if the issues is still relevant.