Incorrect content-length header breaks HTTP/2 with net::err_http2_protocol_error

Created on 3 February 2024, 11 months ago
Updated 30 August 2024, 4 months ago

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.

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
Asset libraryΒ  β†’

Last updated 3 days ago

No maintainer
Created by

πŸ‡«πŸ‡·France frondeau Nantes, FRANCE

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @frondeau
  • There are assets system changes in Drupal 10. Did you have an opportunity to review the release notes?

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

  • πŸ‡«πŸ‡·France frondeau Nantes, FRANCE

    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;

  • πŸ‡«πŸ‡·France frondeau Nantes, FRANCE
  • πŸ‡«πŸ‡·France frondeau Nantes, FRANCE
  • πŸ‡«πŸ‡·France troesler

    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!

  • πŸ‡«πŸ‡·France mably

    Same problem here, Drupal 10.2.2 on PHP 8.1.

    Is any solution available?

  • 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.

  • πŸ‡«πŸ‡·France mably

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

  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    @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.

  • πŸ‡«πŸ‡·France frondeau Nantes, FRANCE

    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.

  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    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?

  • πŸ‡«πŸ‡·France frondeau Nantes, FRANCE

    @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 ?

  • πŸ‡«πŸ‡·France frondeau Nantes, FRANCE

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

  • πŸ‡¬πŸ‡§United Kingdom catch
  • @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.

  • πŸ‡¬πŸ‡§United Kingdom catch

    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.

  • Merge request !6453Resolve #3419024 "Binary file response" β†’ (Open) created by catch
  • Pipeline finished with Success
    11 months ago
    #87905
  • πŸ‡«πŸ‡·France mably

    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.

  • πŸ‡«πŸ‡·France frondeau Nantes, FRANCE

    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.

  • πŸ‡«πŸ‡·France frondeau Nantes, FRANCE
  • πŸ‡¬πŸ‡§United Kingdom catch

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

  • @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.

  • πŸ‡«πŸ‡·France frondeau Nantes, FRANCE

    @catch,
    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-Leght: 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.

  • πŸ‡¬πŸ‡§United Kingdom catch

    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.

  • This is probably due to how HTTP/2 multiplexes.

  • πŸ‡«πŸ‡·France frondeau Nantes, FRANCE

    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 Claro and the message is displayed too.

  • πŸ‡«πŸ‡·France frondeau Nantes, FRANCE

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

  • πŸ‡«πŸ‡·France frondeau Nantes, FRANCE

    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 ?

  • 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.

  • πŸ‡«πŸ‡·France MiniDream

    Hi i have the same problem as you on 10.2.4... 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...

  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    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 is breaking Content-Length somehow.

  • πŸ‡«πŸ‡·France frondeau Nantes, FRANCE

    Hi all,
    thank you to have reported the solution @lonwave.
    Your proposition Header always unset Content-Length in your comment https://www.drupal.org/project/drupal/issues/3419024#comment-15431735 πŸ› Incorrect content-length header breaks HTTP/2 with net::err_http2_protocol_error Active is working for me on Drupal 10.2.2.
    Regards.

  • πŸ‡¬πŸ‡§United Kingdom catch

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

  • πŸ‡¬πŸ‡§United Kingdom catch

    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.

  • πŸ‡«πŸ‡·France MiniDream

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

  • πŸ‡«πŸ‡·France mably

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

  • πŸ‡«πŸ‡·France frondeau Nantes, FRANCE

    @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.
    Regards.

  • πŸ‡³πŸ‡±Netherlands MLZR Zutphen

    #35 + issue https://www.drupal.org/project/drupal/issues/3432990 πŸ› Content-length incorrect and response truncated in web servers Active 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

  • πŸ‡§πŸ‡ͺBelgium michelrrr

    Thanks #35 !!

    My config was :
    OVH
    10.1.8 ALL FINE, no problem
    10.2.x migration => HTTP/2 with net::err_http2_protocol_error

    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>
    
  • πŸ‡§πŸ‡ͺBelgium Fred R

    #35 work for me too on OVH

  • 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);
    
  • πŸ‡«πŸ‡·France sneo

    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 ?

  • πŸ‡¨πŸ‡ΏCzech Republic mkolar

    Same issue on AWS. Currently trying to update to 10.2.4 and got this error..

Production build 0.71.5 2024