If domain access and Drupal core's page caching are both turned on, then pages that have been precached by anonymous users will be displayed to logged in users, giving the appearance of being logged out on some pages.
Steps to reproduce:
1. Enable domain access and anonymous page caching.
2. Add the domain bootstrap to the settings.php file.
3. 'Warm' the page cache by visiting a page as a logged out, anonymous user.
4. In another browser, already logged in, visit the same page.
5. Observe that you now appear logged out.
This is the output of curl. The first shows the headers as an anonymous user, and the second shows the output the page as a logged in user immediately after. The ETag is different, which suggests this hasn't been pulled from the page cache and as well the X-Drupal-Cache header is missing, but the Cache-Control headers show drupal thinks this page is public and cacheable (which it should never do if a user is logged in).
Torrances-Macbook:~ torrance$ curl -I sub.server.com/content/resourcesHTTP/1.1 200 OK
Date: Thu, 16 Jun 2011 00:50:07 GMT
Server: Apache/2.2.16 (Debian)
X-Powered-By: PHP/5.3.6-6~dotdeb.1
X-Drupal-Cache: HIT
Etag: "1308185230-0"
Link: </node/1210>; rel="shortlink",</content/resources>; rel="canonical"
X-Generator: Drupal 7 (http://drupal.org)
Cache-Control: public, max-age=0
Last-Modified: Thu, 16 Jun 2011 00:47:10 +0000
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Vary: Cookie,Accept-Encoding
Content-Type: text/html; charset=utf-8
Via: 1.1 bc3
Connection: Keep-Alive
Torrances-Macbook:~ torrance$ curl -I -b SESS3f0fd158b45beefaee9114d4bfc01f8c=Psg6tQM8tXOuhE_smtinI3amoRYoG_pOLsvBuSUIebg sub.server.com/content/resources
HTTP/1.1 200 OK
Date: Thu, 16 Jun 2011 00:50:22 GMT
Server: Apache/2.2.16 (Debian)
X-Powered-By: PHP/5.3.6-6~dotdeb.1
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Last-Modified: Thu, 16 Jun 2011 00:50:22 +0000
Cache-Control: public, max-age=0
ETag: "1308185422-0"
Link: </node/1210>; rel="shortlink",</content/resources>; rel="canonical"
X-Generator: Drupal 7 (http://drupal.org)
Vary: Cookie,Accept-Encoding
Content-Type: text/html; charset=utf-8
Via: 1.1 bc3
Connection: Keep-Alive
Removing the bootstrap includes line in settings.php stops this from happening.
| Comment | File | Size | Author |
|---|---|---|---|
| #41 | 1189916-base-url-calc-73.patch | 10.32 KB | agentrickard |
| #37 | 1189916-base-url-calc.patch | 5.04 KB | agentrickard |
| #36 | 1189916-base-url-calc.patch | 5.06 KB | agentrickard |
| #32 | liveheaders.txt | 9.37 KB | torrance123 |
| #30 | Screen Recording 7 480p.mov_.gz | 2.23 MB | torrance123 |
Comments
Comment #1
torrance123 commentedIt may be necessary to log out and log back in once both domain access and page caching have been enabled, before you can reproduce the problem.
Comment #2
torrance123 commentedThis is the output of curl, first as an anonymous user and secondly as a logged in user, with the bootstrap file not included in settings.php. The cache-control header is the noticeable difference:
Comment #3
andros commentedI can confirm that
Comment #4
agentrickardWhich version of Drupal? If 7.2, I'm going to scream, since this has worked fine since Drupal 5.
Are you using core caching or an external mode (like varnish)?
What is in {cache_page}, especially, what cache_ids?
Comment #5
agentrickardThis came up before -- see #1046844: domain_bootstrap breaks page cache -- and so if that behavior has changed...
Comment #6
agentrickardI cannot replicate this report in the browser.
Comment #7
agentrickard@andros
Did you confirm this error when running curl?
If not, what browsers? I'm testing on FireFox 4 and Chrome 12 (Max OS 10.6) with no issues.
Comment #8
agentrickardAs logged in (user 1), with a valid matching page in cache.
Comment #9
torrance123 commentedIt's drupal 7.2 with core caching. We had varnish in front of it, but when we encountered these logouts, that was the first thing to go. The problem still persists with a bare apache+mod_php installation.
However, this bug may be really hard to track down as it's not easily reproducible. I haven't been able to reliably set up one page to be logged out through warming the cache - the page on which one is logged out is quite random. But once you come across one, you can navigate away from it and back, and you'll still be logged out *just* on that page.
I ran tcpdump to collect the response headers whilst using Chrome logged in. The first set of headers below show Chrome loading a page properly - displaying me as logged in, and the second you can see I've been returned a 304 based on Chrome including an If-None-Match header and the page is displaying me as logged out.
Comment #10
torrance123 commentedOh! Right, so I've got this slightly wrong. Steps to reproduce:
1. Visit site with domain and page caching enabled. Click through a few links and prewarm your *browser's* cache.
2. Login.
3. Re-visit those pages that you previously visited and you'll appear logged out.
4. Visit other pages (eg. /user ) that you didn't visit before you logged in and you'll appear logged in.
I've tested this on both Chrome and Safari. So it seems to be that the browser is correctly caching the pages when logged out, but that once logged in drupal is simply returning 304s in response to these browsers sending If-None-Match headers and browser is therefore hitting its own cache.
Comment #11
agentrickardOK, just replicated.
/me curses Drupal 7.2
Comment #12
agentrickardBumping.
The steps in #10 work in Chrome to replicate the bug.
Comment #13
agentrickardMore accurate title.
Comment #14
agentrickardNote that this does not appear to happen to user 1.
EDIT: This is actually browser-specific. FireFox 4 doesn't have this problem.
Comment #15
agentrickardAND it doesn't happen in FireFox. But it does in Safari and Chrome.
Comment #16
agentrickardCommenting out
drupal_settings_initialize()in domain.bootstrap.inc solves this problem, but probably causes others.At least that points us to the right place.
Comment #17
agentrickardPatch for 7.x.2.
This does what I tried to avoid in the first place -- replicates core logic to ensure that $base_url is set properly. Seems to work. Porting up to 7.x.3 for testing.
Comment #18
agentrickardPatch for 7.x.3, and tests still pass.
Comment #19
torrance123 commentedHi there - it's great that you've been able to reproduce the bug!
However, I'm still able to reliably reproduce this bug with the patch applied, even after clearing both drupal's and the browser's cache.
Comment #20
andros commented@agentrickard
I can confirm the behavior for my pages. user1 and some other rolls like editors have this problem all the time. mainly we work with Firefox 4, and it happens to me all the time with Firefox 4 too. I can login and see the admin menu but as i visit some other page it seems the i am not login anymore. when i clear the complete drupal cache all went fine and i am logged in on all pages. but when someone visit a page anonymously it happens again to me on this page.
Comment #21
agentrickardOdd. I would swear it worked.
Comment #22
agentrickardOK, another patch. Essentially, we have two choices:
-- Duplicate most of the logic from drupal_initialize_settings().
-- Use a cache handler insert instead.
I don't like either option, but the first requires less work by the site, and doesn't require docs changes.
Comment #23
agentrickardPatch for 7.x.3.
Note that if you manually set $cookie_domain in settings.php, that line MUST go above the include.
Comment #24
agentrickardAnd a 7.x.3 version with a test!
Comment #25
torrance123 commentedThanks agentrickard for your perseverance in this issue, but I am the deliverer of bad news once again: the patch in #22 on drupal 7.2 still doesn't work, and in Chrome, Safari and Firefox included. I can still reliably reproduce the bug.
Comment #26
agentrickardFFS.
Then you need to do some work and tell me what's going on. I have WORKING TESTS in the 7.x.3 branch.
Comment #27
agentrickardWorks fine for me on all browsers. Logged in users stay logged in. Anon users are served cached pages.
What does your settings.php look like?
What URLs are you hitting?
What $cookie_domain (if any) are you setting?
Are you setting $base_url manually? (Don't)
Comment #28
agentrickardAnd an even better test patch for 7.x.3, which passes.
Comment #29
agentrickardLiveHTTP Headers (FireFox) output for test user. Works as designed.
If you say it doesn't, I need lots of detail. (See #27)
Comment #30
torrance123 commentedSee attached for a screencast documenting the issue as well as our settings.php file (for the $cookie_domain and $base_url settings).
Comment #31
torrance123 commentedAnd just to be perfectly clear, by commenting out the bootstrap include line in the settings.php file I am unable to reproduce this bug.
Comment #32
torrance123 commentedThis is liveheaders output on Firefox.
This involved: front page -> front page (again) -> /user/login -> (login redirect) -> /user/torrance -> front page (appear logged out) -> /news (appear logged in).
I cleared both my browser cache and the drupal cache before running this.
Comment #33
torrance123 commentedFuck, should've really cleaned those liveheaders. *goes away to change passwords...*
(Why can't I delete attachments?)
Comment #34
agentrickardThat's really odd and exactly the reverse of what my test shows.
The patch applied cleanly?
Are you doing anything special with www.* handling at the Domain configuration or Apache / mod_rewrite / .htaccess level?
Comment #35
agentrickardOK, the only difference is that I have these lines above the include in settings.php. If I remove them, logins break:
So we need to check $cookie_domain handling.
Comment #36
agentrickardLooks like a session name mismatch caused by the logic loop. This patch should work whether $cookie_domain is set manually or not.
See the notes at line 360:
Porting up to 7.x.3 for testing.
Comment #37
agentrickardOoops. left in a stray debug statement.
Comment #38
torrance123 commentedWicked, patch #37 works like a charm. Thanks very much agentrickard!
Comment #39
agentrickardThe problem was that you aren't setting $cookie_domain to allow shared login -- I always do that first, and I suspect most people do. That explains why this issue wasn't discovered earlier.
Comment #40
agentrickardNote that this issue does not affect Drupal 6.
Comment #41
agentrickardAnd we made the cache tests work, too.
Comment #42
agentrickardCommitted. Thanks, @torrance123!
Comment #43
andros commentedwhen will this get in some stable state, or is there a release coming in version 2.x?
Comment #44
mefisto75 commentedsubscribing to the question above
Comment #45
agentrickardIt's ready for inclusion in 7.x.2 and 7.x.3, pending some reviews of outstanding issues.
http://drupal.org/project/issues/domain?text=&status=8&priorities=All&ca...
Comment #47
camsoft2000 commentedWe are having the same issue with 7.x-2.13 (stable) and tried applying the patch but it failed to patch. We tried to update our site to 7.x-3.x-dev but it completely broke the site and failed to upgrade the database. We've managed to restore the site and reverted to 7.x-2.13
Any chance of this patch being ported to 7.x-2.13, I would be forever in your debt?
At the moment we either have to disable caching on the sites which slows the sites down big time and has been causing us server loads problems or the editors can't edit the site properly as the edit options are gone due to cached pages being loaded.
EDIT: Just realised that there was a 7.x-2.x patch in the above comments. My bad. Sorry.
Comment #48
pieterdt commentedHi, i hope somebody still reads this, certainly because i'm probably not in the right place:
I have the exact same behaviour as mentioned in this ticket, although I'm not using the domain access module.
We have configured caching with Varnish, but this results also in browser caching.
The browser cache shows pages from before the login when they are revisited after the login.
Has someone an idea where i need to start looking?
Comment #49
ktrev commentedI am using 7.x3.10 version and i still have this problem.
My settings.php contains the line
$cookie_domain = '.mysite.in';
I think I am missing something.This patch is already added in this version.I am using drupal 7.22 version.I am using Boost to cache anonymous user page
Please help
Comment #50
agentrickardWell, that sounds like a Boost problem, frankly.
Comment #51
agentrickardYou may also be having a cross-domain login issue. See https://drupal.org/node/1197684 for background.
Comment #52
ktrev commentedYes ,That is a boost problem.I disabled boost for now.. Will post this issue in boost module
Comment #53
ktrev commented