Either the documentation of the setting is completly wrong:

None will allow pages to persist for their full max-age; use this if you want to write your own cache-clearing logic.

Or the code is wrong.
If I look at the function clear, with 0 in this option I'm taking the else part line 67 and this leads to a "varnish_purge_all_pages();".

Please, do not perform any purge operation if we choose "none". We do not need a single drupal server from trying to PURGE billions of pages in Varnish, "None" means, do not care about the proxy-cache cache.

Comments

fabsor’s picture

Status: Active » Needs review
StatusFileSize
new899 bytes

There is a bug in the code. This patch should solve the problem.

regilero’s picture

Thanks,

The patch worked for me. When will it be incorporated in the release?

fabsor’s picture

It will be in the next release when it's status has been set to "Reviewed and tested by community". If you think this fix works for you, you should change the status of this issue. Once that is set, it is an indicator that this is ready to be commited. It is best practice that I don't set this issue to RTBC or fixed myself, since I was the one who created the patch. Once set to Reviewed and tested, I can commit this patch. It will be in the next dev release after 12 hours.

regilero’s picture

Status: Needs review » Reviewed & tested by the community
fabsor’s picture

Status: Reviewed & tested by the community » Fixed

This is finally fixed! Sorry for the wait.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

mattyohe’s picture

As a note for anyone coming across this, this was not rolled into Beta 1, but rather removed right before beta 1 was released in this commit

Then someone else came across this issue and it has been committed to dev

regilero’s picture

Status: Closed (fixed) » Active

So If I look at actual dev code:

 if (!module_exists('varnish') ||
      (variable_get('varnish_flush_cron', 0) && lock_may_be_available('cron')) && !variable_get('varnish_cache_clear', 1)) {
      return;
    }

That means (if I understand well) you do not perform the purge:

  • the module is not installed
  • we said false to varnish_flush_cron AND we are not in a cron AND we said false to varnish_cache_clear

Now if one of theses things is not ok we continue, so for example if we are in the cron. And later the only variable checked will be varnish_cache_clear. So setting varnish_flush_cron to 1 or 0 does not change anything. the purge will be made while we are in the cron...

And effectively, I'have a 'varnish_cache_clear' set to 0 as I do not want any flush from this module into varnish but it is still flushing my varnish at each cron, and setting varnish_flush_cron to 0 which is the default does not change anything. That means having varnish_cache_clear to None is still peerforming purge when the cron is running.

Why not using a simple OR. If someone does not want purges, then never do it.

 if (!module_exists('varnish') ||
      (variable_get('varnish_flush_cron', 0) && lock_may_be_available('cron')) || !variable_get('varnish_cache_clear', 1)) {
      return;
    }

Or clarify in settings. purge is done:

  • on cron and cache clear
  • on cache clear (but not when cron is running)
  • never
regilero’s picture

Version: 7.x-1.x-dev » 7.x-1.0-beta1

Is there a new beta soon where the always-empty-varnish-on-drupal-cron will be fixed?

damienmckenna’s picture

I'm getting this with an Acquia hosting account on a shared dev server. I've tailored the settings.php file so that the Varnish cache backend is only loaded on production and varnish_cache_clear is set to 0 on dev, but it still tries contacting the (non-existent) varnish server on 127.0.0.1:6082 when I run "drush cc all".

damienmckenna’s picture

Version: 7.x-1.0-beta1 » 7.x-1.x-dev
StatusFileSize
new659 bytes

Trying out this patch to see if it will work - it changes the if() statement from:

    if (!module_exists('varnish') ||
      (variable_get('varnish_flush_cron', 0) && lock_may_be_available('cron')) && !variable_get('varnish_cache_clear', 1)) {
      return;
    }

to:

    if (!module_exists('varnish') ||
      !variable_get('varnish_cache_clear', 1) ||
      (variable_get('varnish_flush_cron', 0) && lock_may_be_available('cron'))) {
      return;
    }

This checks to see if the varnish_cache_clear variable is set to 0, i.e. cache_clear integration is disabled, which is IMHO what it should be doing.

simon georges’s picture

Status: Active » Needs review

Changing status to "needs review", as there is a new patch.

sambonner’s picture

StatusFileSize
new631 bytes

Patch in #11 fails for me for two reasons (as far as I can tell). First, lock_may_be_available('cron') is returning false and variable_get('varnish_flush_cron', 0) isn't actually doing a comparision, its just returning whatever varnish_flush_cron is set to.

I've rolled a new patch that fixes these issues, its possible I've misunderstood something about this process and if so I'd be very happy to be enlightened :)

Thanks,
Sam

mgifford’s picture

I'd love to see this issue get resolved. I couldn't test it on SimplyTest.me, but the patch seemed to apply nicely which is a good start.

mgifford’s picture

DUPLICATE

bradjones1’s picture

Title: Varnish Cache Clearing setting "None" is still performing purge » Logic to abort cache clear not working as expected
Priority: Normal » Major
Issue summary: View changes
Related issues: +#1461792: Cache doesn't clear if "varnish_flush_cron" set to 1
StatusFileSize
new666 bytes

Updating the issue title to reflect the fact this not only affects what you'd expect to be a global setting (never clear the cache, even on cron) but also that the don't-clear-on-cron setting currently has no effect.

I re-rolled the patch in #13 to clarify the last two tests and make them consistent with the settings file. Interestingly, there's a simple 0/1 option for varnish_flush_cron, but the same 0/1 options are provided by constants in the form element for varnish_cache_clear. Just in case they ever change, I've used the constants here.

The test that's currently in the -dev branch to abort clearing the cache doesn't look right to me:

(!module_exists('varnish') || (variable_get('varnish_flush_cron', 0) && lock_may_be_available('cron')) && !variable_get('varnish_cache_clear', 1))

which I interpret to mean, don't proceed if:

  • Varnish module is disabled, OR
  • we do want to clear cache on cron and we can get the cron lock, AND we don't want to clear the cache.

This line was inserted with this commit from #1461792: Cache doesn't clear if "varnish_flush_cron" set to 1 but it didn't elicit much discussion or testing at the time.

Also marking as major since this results in Varnish not working as advertised/configured and could significantly limit your cache hit rate if you run cron frequently.

bradjones1’s picture

StatusFileSize
new613 bytes

Apologies - the cron-related conditional should be checking if we want to clear caches on cron, AND that cron is currently running. So we look for the semaphore. The use of lock_may_be_available() doesn't seem to me like it would work; if cron is running it will have the lock, so it's unavailable to us.

EDIT: This is an interdiff, my mistake - see next comment for complete patch.

bradjones1’s picture

StatusFileSize
new709 bytes

Here's the self-contained patch. Sorry to clog up the comment queue.

bradjones1’s picture

StatusFileSize
new702 bytes

Updated: Apparently cron_semaphore is a relic of Drupal 6, even though D7 cleans it up after running system cron. Regardless, this still needs a fix and lock_may_be_available() is probably the best way to test for cron currently running.

mgifford’s picture

The patch applies nicely. I'm trying to test it though and not sure the best approach.

bradjones1’s picture

@mgifford - you're not sure the right approach to test it, you mean?

Locally, I had a window open running a tail -f /var/log/syslog | grep varnish, which allowed me to view the CLI requests being run from varnish module.

In another window or browser, run drush/UI commands that would trigger varnish in various circumstances.

mgifford’s picture

So using this patch with drush cc all I get:

Jan 13 23:08:46 hqdev varnishd[12371]: CLI telnet 127.0.0.1 49601 127.0.0.1 6082 Rd auth LONGRANDOMSTRING
Jan 13 23:08:46 hqdev varnishd[12371]: CLI telnet 127.0.0.1 49601 127.0.0.1 6082 Wr 200 -----------------------------#012Varnish Cache CLI 1.0#012-----------------------------#012Linux,3.2.0-56-generic,x86_64,-smalloc,-smalloc,-hcritbit#012#012Type 'help' for command list.#012Type 'quit' to close CLI session.
Jan 13 23:08:46 hqdev varnishd[12371]: CLI telnet 127.0.0.1 49601 127.0.0.1 6082 Rd ban req.http.host ~ joininfo.ca && req.url ~ "/"
Jan 13 23:08:46 hqdev varnishd[12371]: CLI telnet 127.0.0.1 49601 127.0.0.1 6082 Wr 200

By running cron I get:

Jan 13 23:09:06 hqdev varnishd[12371]: CLI telnet 127.0.0.1 49608 127.0.0.1 6082 Rd auth LONGRANDOMSTRING1
Jan 13 23:09:06 hqdev varnishd[12371]: CLI telnet 127.0.0.1 49608 127.0.0.1 6082 Wr 200 -----------------------------#012Varnish Cache CLI 1.0#012-----------------------------#012Linux,3.2.0-56-generic,x86_64,-smalloc,-smalloc,-hcritbit#012#012Type 'help' for command list.#012Type 'quit' to close CLI session.
Jan 13 23:09:06 hqdev varnishd[12371]: CLI telnet 127.0.0.1 49608 127.0.0.1 6082 Rd status
Jan 13 23:09:06 hqdev varnishd[12371]: CLI telnet 127.0.0.1 49608 127.0.0.1 6082 Wr 200 Child in state running

So how do you "abort cache clear"?

bradjones1’s picture

@mgifford - there are settings on the Varnish module config.

bibo’s picture

I just found out this issue still exists in Varnish-module, and it is wiping varnish way too often. I found it out when doing a performance review for a site, when I simply ran:
varnishlog|grep "Rd ban"

Which revealed those requests:
Rd ban req.http.host ~ site.com && req.url ~ "/"

Would the patches work against Varnish 7.x-1.0-beta2?

bradjones1’s picture

@bibo - probably yes, but development and testing occurs on the -dev branch.

JeremyFrench’s picture

Status: Needs review » Fixed

This works for me. Thanks.

bradjones1’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

marcingy’s picture

Status: Closed (fixed) » Needs work

We finally upgraded the module and this actually breaks any installs using VARNISH_NO_CLEAR as the default as it immediately kills all processing but there is a

if (empty($cid) && variable_get('varnish_cache_clear', 1)) {

check below and then a perfectly valid else that can never be reached.

bradjones1’s picture

Status: Needs work » Closed (fixed)

@marcingy - This was long-closed and has a commit associated with it... If there's a problem now I'd recommend opening a new ticket.

colan’s picture

...and please post a link to it here or tag it as related so we can follow if we wish.