The ban URLs are missing the leading slash.

Using module expire 7.x-2.0-rc3 with these settings:
External expiration selected
Include base URL in expires is NOT checked

Varnish settings:
Varnish cache clearing: Selective
Varnish ban type: Ban Lurker

Using: varnishlog|grep ban

0 CLI - Rd ban obj.http.x-host ~ test.example.com && obj.http.x-url ~ ^$|^node/5669/edit$|^node/3880$|^home$|^node/5669$|^products/testing/amazon-redshift$

I believe that the ban should look like this:
0 CLI - Rd ban obj.http.x-host ~ test.example.com && obj.http.x-url ~ ^/$|^/node/5669/edit$|^/node/3880$|^/home$|^/node/5669$|^/products/testing/amazon-redshift$

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Marshall_Kennard’s picture

The varnish_purge function removes the base path from the pattern, including the leading slash.
Here is a patch to fix it.
I was not sure if base_path always would begin with a slash. If so, this could be simplified to:
$single_pattern = substr_replace($single_pattern, '', 2, strlen($base_path) - 1);

Marshall_Kennard’s picture

Here is the correct patch without the troubleshooting code.

Marshall_Kennard’s picture

david.gil’s picture

Status: Active » Reviewed & tested by the community

patch in #2 is working for me.

frankkessler’s picture

I think we have to think bigger picture here. I don't think the $base_path should be removed at all. That section of code should be removed. Varnish includes the leading slash and any sub-directories in the URL. The $base_path would be included in this. Maybe there's a use case I'm not thinking of, but here's a patch that removes that section of code.

frankkessler’s picture

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

The patch at #5 is working for me. The code in question was added in #2017097: Ban/purge requests to varnish are malformed. if anyone wants to read up on it..

fearlsgroove’s picture

Status: Needs review » Reviewed & tested by the community

+1 for #5 -- a drupal path without a full base path is useless to varnish as far as I can tell, at least with 3.x and up. Is this sillyness supposed to support old 2.x stuff or something?

basvredeling’s picture

+1 for #5

blazingarrow’s picture

Patch #5 was faulty. I've added a new patch.

basvredeling’s picture

Sorry, but #10 makes no sense at all.
You explode() $patterns, run a loop in which you do absolutely nothing, and implode into $patterns again.

Why was #5 faulty?

blazingarrow’s picture

Sorry I was a bit in a rush and overlooked the code completely. I saw a repetitive if statement.

eliosh’s picture

+1 for #5
I tested it also with Domain Access, and it work very well!

opratr’s picture

+1 RBTC for #5
Patch applied cleanly and corrected the problem.
Drupal 7.34
Varnish 7.x-1.0-beta3

cammchugh’s picture

I applied this patch and noticed that it surfaces another issue. When selecting the option in the expire module to also expire the home page, the expire module passes '/' as one of the paths to expire. However, when imploding the paths, this module adds the base path ('/' in my case) to each path. This results in the path '//' for the front page, which is clearly incorrect, and the resulting ban fails to invalidate the home page in varnish:

Rd ban req.http.host ~ localhost && req.url ~ ^//$|^/node/61$|^/some/path$

Would this be considered part of this bug, or a separate issue? I'm leaning towards it being a distinct bug, but I could just update the patch for this issue.

As a side note, patch #5 renders the comment "// Modify the patterns to remove base url and base path." somewhat inaccurate, and leaves behind an unreferenced variable $base_path in the varnish_purge function. If I resubmit a patch for the above noted issues, I'll address these as well.

esolitos’s picture

Priority: Normal » Critical

Same issue there, we donwgraded the module to beta2, I think the priority on this should be quite high, since it basically breaks the possibility to clear the cache!

MiSc’s picture

Status: Reviewed & tested by the community » Needs work

Setting this to needs work because of comment #15.

vinmassaro’s picture

@cammchugh: can you tell me how to reproduce the double slash issue? With Expire 7.x-2.0-rc4 and this patch added, I don't get this behavior. I set it to clear the front page, and when looking at varnishlog when editing a node, here is the ban I am seeing:

Rd ban req.http.host ~ drupal.dev && req.url ~ ^/$|^/node/236469$|^/home$|^/node/739022$|^/test-node$

This looks correct to me. It's expiring the home page and node page, as well as all of their aliases.

cammchugh’s picture

@vinmassaro: I grabbed a clean copy of core, varnish, and expire and also could not reproduce the double slash issue. I went back to the codebase for the project we were working on when I posted #15, and found a couple lines of code tucked away in a custom module added by our team as a partial workaround for this issue. Commented them out and everything functions as expected.

Apologies for the confusion, I believe this can be set back to RBTC.

vinmassaro’s picture

Status: Needs work » Reviewed & tested by the community

@cammchugh: Thanks for checking, moving back to RTBC.

MiSc’s picture

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

  • MiSc committed 211afb2 on 7.x-1.x authored by frankkessler
    Issue #2340829 by Marshall_Kennard, frankkessler, blazingarrow: Leading...
MiSc’s picture

Status: Reviewed & tested by the community » Fixed

Thanks!
Committed to latest dev - I think this is it for getting a new release out.

Status: Fixed » Closed (fixed)

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

pianomansam’s picture

What's stopping a full release containing this fix? I ran into this issue with beta3 and reluctantly have upgraded to the most recent dev version.

natew’s picture

I ran in to the same issue and #5 solved it for me. I needed to rebuild the patch for my build environment, attaching a new version (same changes).