ORIGINAL TITLE: http.response.debug_cacheability_headers TRUE could cause a WSOD - AH01070: Error parsing script headers

I was getting a WSOD with apache 2.4.29_1 and php-fpm 7.1.14 with the following error:

Premature end of script headers: index.php
AH01070: Error parsing script headers

This was happening on a single URL /node/add/XXX of a CT. The rest worked just fine.

I was finally able to sort it out by setting http.response.debug_cacheability_headers to FALSE on development.services.yml.

I then found out this was also mentioned here on #2827047-15: Add http.response.debug_cacheability_headers: true to development.services.yml.

According to @mpotter on #2827047-16: Add http.response.debug_cacheability_headers: true to development.services.yml:

It is actually very common on complex sites to exceed the Apache header size with too many cache tags, especially when logged in as a user looking at a listing page with lots of nodes that are cached per-user because of node-history.

My site is not that complex. It does use paragraphs and a bunch of fields.

Further research pointed me to http://httpd.apache.org/docs/2.4/mod/core.html#limitrequestfieldsize

However, attempting to set any of the following to a grater number didn't help (en either main apache conf and vhost conf)

- LimitRequestFields 100
- LimitRequestFieldSize 8190
- LimitRequestLine 8190

The values above are the default, I increased them with different values, I couldn't make it work. I am not sure if I was doing something wrong or anything but it simply didn't allow me to still access the site on that URL.

I can confirm the cache tag length was 8287 bytes on my particular use case.

Comments

hanoii created an issue. See original summary.

hanoii’s picture

Issue summary: View changes
hanoii’s picture

Issue summary: View changes
hanoii’s picture

Issue summary: View changes
hanoii’s picture

Issue summary: View changes
hanoii’s picture

Issue summary: View changes
liampower’s picture

I stumbled across this error today as well for a specific content type (add/edit).

Whereas setting

http.response.debug_cacheability_header

to false in development.services.yml does allow the page to load, it doesn't fix the underlying issue.

wim leers’s picture

Status: Active » Postponed (maintainer needs more info)

Can you explain why you think this is a bug in Drupal?

hanoii’s picture

Category: Bug report » Task

Well, it's definitely not a bug in Drupal, but, it comes as default on development.services.yml, so it has the potential to fail and it something that I took quite a bit to find the culprit, so maybe document it better even on the yml file, change the default to false?

wim leers’s picture

If you don't notice this problem while developing, what happens if you deploy to production on sites that are using e.g. https://www.drupal.org/project/purge or https://www.drupal.org/project/fastly?

hanoii’s picture

I am not sure I understand your last comment @Wim Leers. Maybe the summary is not clear, but this IS a potential problem ONLY while developing, and it's related to a default limit in apache. It's just the length of the cache tags header, that it could be too big.

EDIT: Well, it could happen on proudction if you enable the debug headers for some reason,

hanoii’s picture

Also I don't see how this relates to the other modules.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

josephdpurcell’s picture

I ran into this issue on Drupal 8.5.5 inside of https://www.drupalvm.com/, default Apache 2.4.18 settings. The issue occurs when docroot/sites/development.services.yml has http.response.debug_cacheability_headers to "true". I confirmed that even with advagg module uninstalled this setting will cause WOSD.

Here is the error I saw in apache error log:

[Wed Jul 18 19:01:30.597148 2018] [proxy_fcgi:error] [pid 1396:tid 140595418789632] [client 10.20.1.1:51824] Premature end of script headers: index.php, referer: http://drupal.local/
[Wed Jul 18 19:01:30.597190 2018] [proxy_fcgi:error] [pid 1396:tid 140595418789632] [client 10.20.1.1:51824] AH01070: Error parsing script headers, referer: http://drupal.local/
[Wed Jul 18 19:01:30.597194 2018] [proxy_fcgi:error] [pid 1396:tid 140595418789632] (22)Invalid argument: [client 10.20.1.1:51824] AH01075: Error dispatching request to : , referer: http://drupal.local/

The solution for me was to change http.response.debug_cacheability_headers to "false".

tanmayk’s picture

Encountered this with 8.5.6. Fixed after setting http.response.debug_cacheability_headers to false.

andres.torres’s picture

I'm experiencing the same issue which is breaking Pound proxy (v. 2.7). Setting http.response.debug_cacheability_headers to FALSE fixes the WSOD. Drupal core 8.6.1.

cgmonroe’s picture

I hit this problem as well when re-syncing my development site to the current production site.

It is a Drupal bug because Drupal code produces a header that breaks Apache's rules. The code to produce this tag should not create a tag greater then the standard Apache limit. Instead it should break them up to multiple X-Drupal-.. tags.

The current code simply implodes the list of cache and context tags without checking it's length. The code should do something like the psuedo code below for both X-Drupal-Cache-Tags and X-Drupal-Cache-Contexts tags.

<?php
static MAX_LENGTH = 8000; // A bit of headroom from the 8190 Apache max
$cache_tags = implode(' ', $response_cacheability->getCacheTags()));
if ( strlen($cache_tags) < MAX_LENGTH ) {
  $response->headers->set('X-Drupal-Cache-Tags', implode(' ', $response_cacheability->getCacheTags()));
}
else {
  // loop thru cache tags testing length and setting multiple headers with shortened cache tag value
}
?>
cgmonroe’s picture

Title: http.response.debug_cacheability_headers TRUE could cause a WSOD - AH01070: Error parsing script headers » X-Drupal-Cache-Tags / X-Drupal-Cache-Context header tags can exceed HTTP Server limits and cause WSOD
Category: Task » Bug report
Issue summary: View changes
Status: Postponed (maintainer needs more info) » Active

Updated the title to indicate bug.

Changed category to bug since Drupal is causing the WSOD

Changed Status to active since there is a proposed strategy for fixing this.

remram’s picture

We are running to the same error as #14 We are wondering if someone knows the progress about this bug. Does Drupal follow this bug or not? Thank you guys, for further information.

We are using Apache 2.4.29-1ubuntu4.5 and PHP php-fpm 7.2.10-0ubuntu0.18.04.1

cilefen’s picture

Does Drupal follow this bug or not?

Yes. This is the Drupal issue queue.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

vaza18’s picture

Status: Active » Needs review
StatusFileSize
new1.65 KB
vaza18’s picture

vaza18’s picture

mpotter’s picture

Status: Needs review » Needs work
+++ b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php
@@ -154,8 +154,14 @@ public function onRespond(FilterResponseEvent $event) {
+      foreach (explode("\n", wordwrap($cache_tags, 8000)) as $delta => $tags) {

8000 should not be hard coded. At least needs a constant (for both places it is used)

michaellenahan’s picture

Status: Needs work » Needs review
StatusFileSize
new2.03 KB
mr.baileys’s picture

Status: Needs review » Closed (duplicate)

This issue seems to be a duplicate of #2844620: Automatically split cache debug headers into multiple lines when they exceed 8k. Since that issue is older, I'm closing this one in favor of the older one.

The hardcoding of the maximum length is discussed in that issue, as well as a possible solution to dynamically determine the max header size.

jedgar1mx’s picture

Thanks @michaellenahan the patch fixed my issue. If this issues is getting close, the patch probably should get added to the older issue.

michaellenahan’s picture

Credit belongs to vaza18 for a very elegant solution. I simply added some boilerplate code. It would be nice to get this resolved, this issue has caused a lot of unnecessary pain for developers.

merryfreespace’s picture

Thanks @michaellenahan, the patch fixed the issue.

ifrik’s picture

Thanks so much michaellenahan

that saved my day after hours of dealing with a server with restricted access and useless logs. And then applying this patch and hours of agony came to an end....

司南’s picture

Got this pain in drupal 8.9.7 dev mode, the solution was `drupal smo prod`.

司南’s picture

Version: 8.8.x-dev » 8.9.x-dev
miedward’s picture

Update for patch in #21 against 9.2.x since I'm still using it

richirm77’s picture

The same bug reported in ASF Bugzilla:

https://bz.apache.org/bugzilla/show_bug.cgi?id=64919

I have not found if this is fixed by Apache.

miedward’s picture

Update of the previous patch for 9.3.x

anybody’s picture

akz’s picture

Until the fix is merged into core, here is a re-rolled version of patch#36 that uses the sorted cache tags prior to splitting. Also note that this patch is applicable for Drupal 10.4.x as well.

akz’s picture

Alternatively, contrib module Debug Cacheability Headers Split to overcome this issue.