Problem/Motivation

After a migration from Drupal 9.5.11on to 10.2.2 on OVH mutualized server, the document is not loaded, JS files are not running and the error err_http2_protocol_error error is diplayed in the console.

Please feel free to move this question to another Drupal place if needed.

Steps to reproduce

I'm migrating Drupal 9.5.11 to 10.2.2 on

  • a mutualized OVH,
  • Apache2
  • PHP 8.2
  • Mysql
  • Https
  • With ssl on PROD
  • Without ssl on PReprod

I'm notifiying that the behavior is the same on PREPROD and PROD. The production has been rolled back on Drupal 9.5.11 and is working well. The migrated website on local is working well.
An issue is showing in the console: <site url> net:err_http2_protocol_error
After having configured $settings['file_assets_path'], the css and js are well loaded in the network panel, but the issue <site url> net:err_http2_protocol_error is still displayed in the console, the CSS are OK, but JS files are not working.
As many posts are talking about the browsers versions, extensions …, I've updated all my browsers, as said in this example:https://kinsta.com/knowledgebase/err_http2_protocol_error/

In Firefox:
all the assets are well loaded but not the main document:
All the assets are loaded in less than 100ms.
The main document is loaded in 9349ms.
Is it the main reason why the error net:err_http2_protocol_error appears ?
Before the migration, in Drupal 9.5.1, the main page was loaded in 871s and the website is well working.

In Chromium:
The network is showing every assets loaded but not the main document 325B (6.10s), 140,09ko.

  • The CSS are loaded and applied.
  • The JS files are loaded but aren't applyable. Some animations are missing.

In last version, the network is showing a heavier document, 31.3KB, for 805ms and the website is working well.

Who would have encountered the same behaviour or have a solution for this ?
This migration is not valid.
Thank you by advance. Regards.

CommentFileSizeAuthor
Firefox_heavy.png258.12 KBfrondeau

Issue fork drupal-3419024

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

frondeau created an issue. See original summary.

cilefen’s picture

Category: Bug report » Support request
Priority: Critical » Normal
Issue tags: -JS aggregation, -animation

There are assets system changes in Drupal 10. Did you have an opportunity to review the release notes?

cilefen’s picture

I made this a support request so we can gather more information.

frondeau’s picture

Hello @Cilefen,
Thank you for your feedback.
Which pages would reply to my issue, please, ?
Would you post the concerned urls ?
Thank you by advance,
Regards;

frondeau’s picture

Issue summary: View changes
frondeau’s picture

Issue summary: View changes
cilefen’s picture

I don’t remember ever having seen it with Drupal. See also https://stackoverflow.com/questions/58215104/whats-the-neterr-http2-prot...

troesler’s picture

I have the same problem with OVH :

  • PHP 8.1
  • Mysql
  • https
  • Drupal 10.2.2 fresh install.

Here is my test url : https://drupal1022.monsitedev.com
You may see the error on Chrome on the front page
I spended hours of researches and tests in vain, so if a kind soul is willing to solve this problem, I will be forever grateful!

mably’s picture

Same problem here, Drupal 10.2.2 on PHP 8.1.

Is any solution available?

EDIT: Looks like the content-length header on gzipped CSS and JS assets is incorrect (uncompressed size?).

cilefen’s picture

Also OVH?

cilefen’s picture

There is a lot of debugging advice in https://stackoverflow.com/questions/58215104/whats-the-neterr-http2-prot.... If you haven’t done those things you haven’t done everything.

mably’s picture

It looks like Drupal sends an invalid "content-length" header for JS and CSS gzipped assets on first load.

Disabling gzip using SetEnv no-gzip 1 in my .htaccess file fixes the problem, but that's not really a solution.

longwave’s picture

@mably if you can reliably reproduce that with a set of steps that would be really helpful, as we can turn it into a test case.

frondeau’s picture

Hello all,
Thank you for your feed backs, I fell less alone ;-)
I can confirm that there is a difference between D9 and D10.2.2 as there is a Content-Length in the header, reporting the file size.
It' seems that in my case, the docment has a size of 32KB.
All the other files are loaded from memory (0KB) or heavy less equals 5.5KB.
Is Content-Length usefull ?
If so, what would happen if the code set it to -1?
Thanks by advance.

longwave’s picture

Content-Length was added to fix other issues: https://www.drupal.org/node/3298551

However perhaps this is now incorrectly calculated in the case of gzipped content?

frondeau’s picture

@Cilefen,
About the link you're sharing, https://stackoverflow.com/questions/58215104/whats-the-neterr-http2-protocol-error-about, many answers are talking about the environment size and the cpu, but in my case, the website is about 2% of the disk size, and the memory is not full used neither.
As the error message is about HTTP/2, it seems to be due to the protocol, so maybe the answer would be about the header, woudn't it ?

frondeau’s picture

Thank you for your feedback @longwave, I guess the subject is Content-Length too.

catch’s picture

Version: 10.2.x-dev » 11.x-dev
Category: Support request » Bug report
cilefen’s picture

Title: net:err_http2_protocol_error on Drupal 10.2.2 on production err_http2_protocol_error » Incorrect content-length header breaks HTTP/2 with net:err_http2_protocol_error
Priority: Normal » Major

@frondeau

Wrong content-length header is mentioned a lot at https://stackoverflow.com/questions/58215104/whats-the-neterr-http2-prot.... There are many possible answers.

catch’s picture

I've opened an MR with a potential fix - to just stop adding the content length header for BinaryFileResponse (which is what the first asset request returns). Would be great if people experiencing this issue on OVH could try it out (at least once we've had a green test run here). We should probably add some minimum test coverage to the existing content length tests to make sure files are skipped too.

Can you confirm that asset aggregates are actually getting written and this problem is only for the first request that builds them? After that they should be served as actual files and would expect it to work again.

If the server gzips the response from Drupal, it should also be responsible for updating the content length header, so this is perhaps mis-configuration on OVH's side? But also don't feel that we have a strong use case for setting the content length header for binary files and if we can save people hours/days of fruitless debugging that would be good.

mably’s picture

The proposed fix doesn't seem to work on my side.
Looks like we never go through the related code when generating aggregated CSS and JS.
But may be I'm doing something wrong.

frondeau’s picture

Hi @catch,
Thank you for your MR.
I can't test this MR as it is pull from 11.x.
But I could test if you create a MR on 10.2.2, on a real website.
Would you have any time to repeat it on this version, please ?
Thank you by advance.

frondeau’s picture

Title: Incorrect content-length header breaks HTTP/2 with net:err_http2_protocol_error » Incorrect content-length header breaks HTTP/2 with net::err_http2_protocol_error
catch’s picture

@frondeau you should be able to use the diff from https://git.drupalcode.org/project/drupal/-/merge_requests/6453.diff with a 10.2.x site, the affected code is identical.

cilefen’s picture

@frondeau I don't understand your question. The diff, https://git.drupalcode.org/project/drupal/-/merge_requests/6453.diff, applies to the 10.2.x branch as well as to version 10.2.2.

frondeau’s picture

@catch,
thanks for the dif.
after having applyed the patch, cleared the browsers cache, cleared Drupal caches, the issue is still the same, on the document: "Failed to load resource: net::ERR_HTTP2_PROTOCOL_ERROR"
Document Content-Lenght: 138720
Content-Encoding: gzip

Additional information:
On the first page load, the error is displayed on css_* and js_* and document.
On the second page reload: the message is displayed only on document while all the assets are loaded from memory.

catch’s picture

On the second page reload: the message is displayed only on document

Can you try temporarily disabling CSS and JavaScript aggregation (admin/config/development/performance) and let us know if you still see the same error anywhere? If so, then this isn't specific to BinaryFileResponse at all and could be a much wider problem with the content length header.

cilefen’s picture

This is probably due to how HTTP/2 multiplexes.

frondeau’s picture

Hi @catch, @cilefen,
I've removed the aggregation of css/js.

  • On the authenticated as admin on BO, JS and CSS are applied, there's no error message in the console.
  • On anonymous session, the message "Failed to load resource: net::ERR_HTTP2_PROTOCOL_ERROR" is still displayed on the document file.

FYI, I've already tested the front theme with a standard one as Claro and the message is displayed too.

frondeau’s picture

Thanks for your answer, @alexpott,
I'll prepare some debug messages to check the ContentLength handle and give a feedback on the conversation..

frondeau’s picture

Hi all,
Before adding logs in Drupal 10.2.2, I've created another migration with Drupal 10.1.8.
This version seems to work well at first sight:

  • no message in the console
  • JS are working
  • No errors in dblog

Some functional tests will follow to confirm, but it is promising as this.
How can we solve the error "Failed to load resource: net::ERR_HTTP2_PROTOCOL_ERROR" version 10.2.2 ?

Okita974’s picture

Hi,

I have exactly the same problem as you with the same configuration. Strangely, there's no problem when I'm logged in, only when I'm anonymous.

MiniDream’s picture

Hi i have the same problem as you on 10.2 after a migration from 9.5.. and im on OVH too
to add more information, i got the same error on some ajax update request such as custom batch step who need me manualy refresh the page to see what batch update.. and somme other custom ajax request ending the same way...

longwave’s picture

I wonder if this is the same as the issue described at https://github.com/symfony/symfony/issues/46449#issuecomment-1140985890 - which also related to Drupal and the Content-Length header on OVH hosting.

It appears that zlib.output_compression is not enabled on OVH but perhaps they are doing something else to compress content which means Content-Length is incorrect.

A non-Drupal issue where the solution is also to unset the Content-Length header on OVH: https://help.nextcloud.com/t/shared-hosting-ovh-web-nextcloud-issue-with...

Anyone affected by this can try adding this to their .htaccess:

Header always unset Content-Length
frondeau’s picture

Hi all,
thank you to have reported the solution @longwave.
Your proposition Header always unset Content-Length in your comment https://www.drupal.org/project/drupal/issues/3419024#comment-15431735 is working for me on Drupal 10.2.2.
Would you update the .htaccess file to add this option for the "OVH case" or "net::err_http2_protocol_error" ?
Regards.

catch changed the visibility of the branch 3419024-binary-file-response to hidden.

catch’s picture

Hid the MR because that was a complete red herring.

@frondeau Drupal's .htaccess file is intended to be modifiable, we won't add OVH-specific information in there since it could get confusing for sites that don't run into this problem.

However we could add this information to the change record for the issue that added the content length header and/or Drupal 10.2.0 release notes as a known issue.

MiniDream’s picture

Hi Everyone, #35 @longwave work for me too.

mably’s picture

#35 seems to also fix some stability problems when running locally on Docker (Drupal 10.2.3, PHP 8.3, Apache with Nginx proxy).

frondeau’s picture

@catch,
I agree with you to avoid the comment ot include "OVH" term but this solution could be added as comment with a title of type "In case of ContentLength issue"
As a comment, it could provide a direct solution for the developers.
A information about it in the release notes should be good too. Thanks.
Regards.

mlzr’s picture

#35 + issue https://www.drupal.org/project/drupal/issues/3432990 works for me.

1. Set 'Header always unset Content-Length' in the .htaccess AND
2. Patch /public_html/core/lib/Drupal/Core/StackMiddleware/ContentLength.php #48:
From: $response->headers->set('Content-Length', strlen($content), TRUE);
To: $response->headers->set('Content-Length', strlen($content)+2, TRUE);

Thanks @longwave and the referrer to issues #3432990

Marcel

michelrrr’s picture

Thanks #35 !!

My config was :
OVH
10.1.8 ALL FINE, no problem
10.2.5 migration => HTTP/2 with net::err_http2_protocol_error + slowness

Solved by adding 'Header always unset Content-Length' in .htaccess of www

<IfModule mod_headers.c>
         Header onsuccess unset X-Content-Type-Options
         Header always set X-Content-Type-Options nosniff
Header always unset Content-Length
        RequestHeader unset Proxy
</IfModule>

This community is awesome ;)

fred r’s picture

#35 work for me too on OVH

sweepchild’s picture

Hi everyone!

It was an image upload issue on my side and got errors. First patched like below; the error gone, uploaded successfully.

Patch /public_html/core/lib/Drupal/Core/StackMiddleware/ContentLength.php #48:
From: $response->headers->set('Content-Length', strlen($content), TRUE);
To: $response->headers->set('Content-Length', strlen($content)+2, TRUE);

But then some http2 protocol errors appeared on XHR requests. After billion attempts, changed the patch like (switching from +2 to +1) and errors gone forever.

$response->headers->set('Content-Length', strlen($content)+1, TRUE);
sneo’s picture

Same error for me with 10.3.2.
With #35 the loading of my Js continue, but i can have some slowness for some page.
It' very visible because the first image to be loaded is a 50px of width (then the correct image is loaded ) Some page may took 1sec or more to complete load properly.

So for me, it's not really a complete solution.

All was fine on my Dev server (Nginx) but as soon i migrate to an OVH performance ... Issues on chrome.
Does anyone had the same issue on another environment ?

Edit: it seems that when the slowness occur is when ressources are loaded on after the other. Not in parallel. So if there is a lot of JS ressources, it took way longer :)

mkolar’s picture

Same issue on AWS using CloudFront, Load balancer and WAF (not sure where is a problem, on D9 it was ok). Currently trying to update to 10.2.4 and got this error..

jasonsafro’s picture

I wrote a patch for a content-length issue I encountered. I'm not sure if the issues are related but here's the other issue: https://www.drupal.org/project/drupal/issues/3494148

nicolas bouteille’s picture

Hello,
Same here:
OVH performance
D 10.4.1
PHP 8.1.29
#35 solves it for me as well thanks!
However, my .htaccess is not versionned and re-created by core-composer-scaffold on every composer install... how do you suggest I apply this fix? How do you guys handle it?

tostinni’s picture

@nicolas bouteille you can use this in your composer.json to patch it during scafolding :

    "extra": {
        "drupal-scaffold": {
            "file-mapping": {
                "[web-root]/sites/development.services.yml": false,
                "[web-root]/.htaccess": {
                    "prepend": "patches/drupal/3419024.txt"
                }
            },

And then you put this code in patches/drupal/3419024.txt

# Fix error on OVH due to incorrect content-length header
# https://www.drupal.org/project/drupal/issues/3419024

<IfModule mod_headers.c>
  Header always unset Content-Length
</IfModule>

nicolas bouteille’s picture

thank you for the quick reply! gotta try this! there is one thing though, I installed Shield and it looked like enabling / disabling it did rewrite .htaccess thus erased my custom modifications... I have to test it more thoroughly though.

nicolas bouteille’s picture

Thank you your solution works perfect! and Shield module does not actually work with .htaccess so no pb.
Still curious to understand why this is only happening with OVH though and only since pretty recently as well...

nicolas bouteille’s picture

Shame on me: I faced this problem again recently and totally forgot that I had already solved it earlier! And I did not find this issue when I googled it. Or maybe it is because I did not Google it but asked ChatGPT instead ^^
Hopefully OVH support did answer me and provided me with an article with the same solution.
https://habeuk.com/fr/drupal-neterrhttp2protocolerror

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.