Problem/Motivation

When I enable maintenance mode on my website, anonymous users do not see the maintenance page.
I noticed that if maintenance mode is enabled, the `AnonymousLoginSubscriber` class is not called because the response is cached. Therefore, we need to clear the page cache when enabling maintenance mode.

Steps to reproduce

  1. Visit the site as an anonymous user.
  2. Log in using another browser and enable maintenance mode.
  3. Reload the page you visited in the first step (please ensure the URL does not point to the user/login path)

Result: You still see the login form.
Expected: You should see the maintaince page.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

segi created an issue. See original summary.

rajat4u’s picture

Assigned: Unassigned » rajat4u

Working on it.

rajat4u’s picture

Assigned: rajat4u » Unassigned
Status: Active » Needs review
kanchan bhogade’s picture

StatusFileSize
new79.04 KB
new69.29 KB

Hi
I've tested MR !15 on Drupal 11.x
Applied MR successfully...

Testing Steps:
Visit the site as an anonymous user.
Log in using another browser and enable maintenance mode.
Reload the page you visited in the first step (please ensure the URL does not point to the user/login path)

Manual Test Result:After MR, The maintenance page is appears and not showing any path to login (/user/login )

Attaching Screenshot
Keeping in review for code verification

arunsahijpal’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new111.8 KB
new186.5 KB
new194.96 KB

Good work @rajat4u ,
I tested this issue on my local and by applying the MR the issue is completely resolved as maintenance page is shown without clearing the cache.
Attaching ss for reference.

Hence moving it to RTBC.

Thanks
Arun

anton4uk made their first commit to this issue’s fork.

anton4uk’s picture

Status: Reviewed & tested by the community » Needs review

Thanks, @rajat4u and the testers. MR !15 fixes the reported steps, but I opened an alternative MR for the following reasons:

  • Maintenance mode is stored in State, not config. It also clears caches on every config save while the site is in maintenance mode.
  • Clearing rendered, node_list, and config is too broad. The stale entries are in the page cache, and core tags them all with http_response.
  • The test uses expects($this->any()), so it passes even without the fix.

My MR adds a submit handler to the maintenance mode form. It clears http_response only when the setting changes. It leaves the subscriber and its constructor unchanged. It also adds a functional test that fails without the fix.

Note: setting maintenance mode from drush still needs drush cr, the same as in core.

  • anton4uk committed c77885f0 on 8.x-2.x
    Issue #3500544: Invalidate page cache when maintenance mode is toggled
    
anton4uk’s picture

Status: Needs review » Fixed

Merged MR !23. Thanks @segi for the report, @rajat.dkte for the first MR, and @kanchan bhogade and @arunsahijpal for testing. MR !15 is closed.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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