Minify html breaks pages in Drupal 10.2

Created on 17 December 2023, about 1 year ago
Updated 8 January 2024, 12 months ago

Problem/Motivation

I have installed Drupal 10.2 with minifyhtml and after the update I get SSL errors.
I also reported this to Drupal project issue but after some investigation it seems that minifyhtml is breaking the site.
After uninstalling the module the site works again.

Error message in console is: ERR_QUIC_PROTOCOL_ERROR

πŸ› Bug report
Status

Closed: works as designed

Version

2.0

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany sense-design MΓΌnster

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

Merge Requests

Comments & Activities

  • Issue created by @sense-design
  • πŸ‡©πŸ‡ͺGermany Frank.dev

    Same.

  • πŸ‡¬πŸ‡§United Kingdom danthorne Devon, UK

    +1

  • πŸ‡¬πŸ‡§United Kingdom danthorne Devon, UK
  • πŸ‡©πŸ‡ͺGermany sense-design MΓΌnster

    I am also investigation but with DDEV the error is not reproducable. Trying with a snapshot of the productive environment and see what happens.

    Will respond as soon as possible with my investigations.

  • πŸ‡¬πŸ‡§United Kingdom danthorne Devon, UK

    Same. Issue is only present on our production server and when not logged in. Fine in ddev

  • Assigned to slydevil
  • Status changed to Postponed: needs info about 1 year ago
  • πŸ‡¨πŸ‡¦Canada slydevil Halifax

    I spun up a test site - https://master-7tjf71h6euc42njvewo8pyv5jvdx0712.tugboatqa.com/ - and I don't see any issues. The latest minifyhtml version (2.0.3) is installed on this test site.

    The username/password is 'admin'.

    Please visit the test site and let me know if you are still having the issue.

    There must be something specific about your site that is incompatible with the module. After searching (I had never heard of this protocol before) this is the top result: https://kinsta.com/knowledgebase/err_quic_protocol_error/. I'm not suggesting that disabling the protocol is the answer as it's default browser functionality, but it could be related to an incompatible browser extension or proxy settings.

    If you can provide a copy of the unminified HTML, I can use the module to minify it and see what happens.

  • πŸ‡©πŸ‡ͺGermany sense-design MΓΌnster

    This is related to http3 with nginx which is using quic (udp) for connection.

  • I do not think it is related to http3. I am using nginx/1.22.1 (no http3) with PHP-FPM 8.2 and I am also getting issues on my DEV site when Minified Source HTML is enabled.

    When I use the search form to search for VALUE, it works. But when I search for VALUE again, I get a blank page and the following error in the console:

    Failed to load resource: net::ERR_INCOMPLETE_CHUNKED_ENCODING

    I can clear caches, but the error returns. It only keeps working when I disable Minified Source HTML.

  • πŸ‡¬πŸ‡§United Kingdom danthorne Devon, UK

    We are using Apache, PHP-FPM 8.1

  • πŸ‡¨πŸ‡¦Canada slydevil Halifax

    @sense-design I will try your config and see what happens.

    @sd123 not saying that your issue is unrelated, but going to focus on the QUIC error first.

    @danthorne are you using http3?

  • πŸ‡©πŸ‡ͺGermany sense-design MΓΌnster

    @slydevil, if required I can give you access to a copy of the site with the error.

  • @slydevil: I may be wrong, but I do not think it is already possible to use http3 with Apache.

    @danthorne: can you try to temporarily disable PHP-FPM and use mod_php instead? If that works, the errors are maybe correlated with how Drupal 10.2 interacts with PHP-FPM.

  • πŸ‡©πŸ‡ͺGermany zcht

    I have the same problem, I use Config Split for the stage and production environments. Locally the minifiyng is deactivated. Just rolled out a current version with Drupal 10.2, PHP 8.1.26, HTTP/2 nginx 1.24.0 on the stage. After the deployment I always do standardised tests, I noticed that neither *.js nor html were minified. under en/admin/config/development/performance I saw that the checkboxes for Minified Source HTML. and Minified JavaScript files. were not activated (although set in the configuration). When trying to activate them, the following error message appears, the form cannot be saved: 'stale_file_threshold' is not a supported key.

    In the dblog I find the following on the stage, but everything was fine locally:

    Deprecated function: preg_quote(): Passing null to parameter #1 ($str) of type string is deprecated in Drupal\Core\Path\PathMatcher->matchPath() (line 82 of /var/www/vhosts/site/stage/docroot/core/lib/Drupal/Core/Path/PathMatcher.php)
    #0 /var/www/vhosts/site/stage/docroot/core/includes/bootstrap.inc(164): _drupal_error_handler_real()
    #1 [internal function]: _drupal_error_handler()
    #2 /var/www/vhosts/site/stage/docroot/core/lib/Drupal/Core/Path/PathMatcher.php(82): preg_quote()
    #3 /var/www/vhosts/site/stage/docroot/modules/contrib/minifyjs/src/MinifyJs.php(296): Drupal\Core\Path\PathMatcher->matchPath()
    #4 /var/www/vhosts/site/stage/docroot/modules/contrib/minifyjs/minifyjs.module(21): Drupal\minifyjs\MinifyJs->loadAllFiles()
    #5 /var/www/vhosts/site/stage/docroot/core/lib/Drupal/Core/Extension/ModuleHandler.php(545): minifyjs_form_system_performance_settings_alter()
    #6 /var/www/vhosts/site/stage/docroot/core/lib/Drupal/Core/Form/FormBuilder.php(841): Drupal\Core\Extension\ModuleHandler->alter()
    #7 /var/www/vhosts/site/stage/docroot/core/lib/Drupal/Core/Form/FormBuilder.php(284): Drupal\Core\Form\FormBuilder->prepareForm()
    #8 /var/www/vhosts/site/stage/docroot/core/lib/Drupal/Core/Form/FormBuilder.php(224): Drupal\Core\Form\FormBuilder->buildForm()
    #9 /var/www/vhosts/site/stage/docroot/core/modules/system/src/Controller/PerformanceController.php(24): Drupal\Core\Form\FormBuilder->getForm()
    #10 [internal function]: Drupal\system\Controller\PerformanceController->build()
    #11 /var/www/vhosts/site/stage/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
    #12 /var/www/vhosts/site/stage/docroot/core/lib/Drupal/Core/Render/Renderer.php(627): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #13 /var/www/vhosts/site/stage/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext()
    #14 /var/www/vhosts/site/stage/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
    #15 /var/www/vhosts/site/stage/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #16 /var/www/vhosts/site/stage/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
    #17 /var/www/vhosts/site/stage/docroot/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle()
    #18 /var/www/vhosts/site/stage/docroot/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
    #19 /var/www/vhosts/site/stage/docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
    #20 /var/www/vhosts/site/stage/docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
    #21 /var/www/vhosts/site/stage/docroot/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle()
    #22 /var/www/vhosts/site/stage/docroot/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
    #23 /var/www/vhosts/site/stage/docroot/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
    #24 /var/www/vhosts/site/stage/docroot/modules/contrib/remove_http_headers/src/StackMiddleware/RemoveHttpHeadersMiddleware.php(49): Drupal\Core\StackMiddleware\AjaxPageState->handle()
    #25 /var/www/vhosts/site/stage/docroot/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\remove_http_headers\StackMiddleware\RemoveHttpHeadersMiddleware->handle()
    #26 /var/www/vhosts/site/stage/docroot/core/lib/Drupal/Core/DrupalKernel.php(704): Drupal\Core\StackMiddleware\StackedHttpKernel->handle()
    #27 /var/www/vhosts/site/stage/docroot/index.php(19): Drupal\Core\DrupalKernel->handle()
    #28 {main}
  • Status changed to Active 12 months ago
  • πŸ‡©πŸ‡ͺGermany zcht
  • πŸ‡¨πŸ‡¦Canada slydevil Halifax

    @zcht, that looks related to minifyjs and not this module. Please open an issue on that module for that issue.

  • πŸ‡¨πŸ‡¦Canada slydevil Halifax

    @sense-design, I created a minifyhtml channel on the Drupal slack, you can find me there are we can work through this.

  • πŸ‡©πŸ‡ͺGermany sense-design MΓΌnster

    I am in.

  • πŸ‡©πŸ‡ͺGermany sense-design MΓΌnster

    So after some research and additional setup of a copy of the site based on Drupal 10.2 the following error shows up in the nginx error log.

    2023/12/19 14:24:57 [error] 27275#27275: *11131 upstream prematurely closed FastCGI request while reading upstream, client: CLIENT-IP, server: DOMAIN.TLD, request: "GET / HTTP/2.0", upstream: "fastcgi://unix:/run/php/php8.1-fpm.sock:", host: "DOMAIN.TLD"
    

    The errors in the browser console are

    1. ERR_QUIC_PROTOCOL_ERROR
    2. ERR_HTTP2_PROTOCOL_ERROR
  • Status changed to Postponed: needs info 12 months ago
  • If this can help: my DEV site does not have ssl and so neither http2 is used in nginx.

  • πŸ‡©πŸ‡ͺGermany zcht

    @slydevil actually, the problem has nothing to do with minifyhtml or minifyjs. if both modules are uninstalled on the stage, the form simply cannot be saved. it's just an idea that it might also be related to this problem after the update to drupal 10.2. with drupal 10.1 I had absolutely no problems, so something must have been changed in drupal 10.2 that you now have this problem.

    i also found this issue, which doesn't quite fit the topic, but sounds similar only with a different outcome: πŸ“Œ Remove the aggregate stale file threshold and state entry Fixed .

  • πŸ‡©πŸ‡ͺGermany didumir

    Something slightly different here: with D10.2 and minifyhtml enabled, I get ERR_CONTENT_LENGTH_MISMATCH e.g. in Chrome, site works after diabling minifyhtml.

  • πŸ‡©πŸ‡ͺGermany sense-design MΓΌnster

    I found that the problem is somewhere here

    if (!empty($this->placeholders)) {
      foreach (array_reverse($this->placeholders, TRUE) as $placeholder => $value) {
        $this->content = str_replace($placeholder, $value, $this->content);
      }
    }
    

    If I comment the third line no errors are thrown anymore so something with the placeholders is not working correctly anymore or causing some issues with the correct replacement.

  • πŸ‡©πŸ‡ͺGermany sense-design MΓΌnster

    Maybe I found the issue, the ERR_CONTENT_LENGTH_MISMATCH made me think about it and I changed one line to recalculate the content length because the minify process make the response smaller.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update 12 months ago
    7 pass
  • Status changed to Needs review 12 months ago
  • πŸ‡©πŸ‡ͺGermany sense-design MΓΌnster
  • Merge request !102.x β†’ (Open) created by sense-design
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update 12 months ago
    7 pass
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update 12 months ago
    7 pass
  • πŸ‡©πŸ‡ͺGermany sense-design MΓΌnster

    Rerolled the patch to replace the current "Content-Length" in Header.

  • Status changed to Postponed: needs info 12 months ago
  • I disabled the Minified Source HTML checkbox and trying to reactivate, I am now getting the same error as @zcht. Even deinstalling the module does not work

  • πŸ‡©πŸ‡ͺGermany zcht

    @sd123: I was able to solve the problem with the error, here in the issue πŸ’¬ Aggregation not working css and js cache directories not being created Postponed: needs info , comment #42. after that I can deactivate and activate the module. but as soon as I activate the module, I have the problem with ERR_QUIC_PROTOCOL_ERROR.

    i will test the patch from comment 27 soon and hope it helps, thanks for the work @sense-design

  • Status changed to RTBC 12 months ago
  • πŸ‡©πŸ‡ͺGermany zcht

    Patch in comment #27 works great, from my side RTBC+

  • πŸ‡ͺπŸ‡ͺEstonia ragnarkurm

    The patch works in a sense that pages are loading now.
    But in Nginx logs there are now following errors:

    upstream sent more data than specified in "Content-Length" header while reading upstream

    It seems not to happen on every page. I didn't do a thorough testing, but it seems to happen on node pages and not in admin pages.

  • πŸ‡ͺπŸ‡ͺEstonia ragnarkurm

    Simple manual testing seems to indicate that minifyhtml appears to break Big Pipe too. Some Big Pipe items are not loading. Nothing in Network not Console tab about this. The HTML seems to be broken. After disabling the minifyhtml along with the patch, the ending of the page is now good.

    minifyhtml installed and patched:

    minifyhtml uninstalled:

  • Good news! As far as I can see Drupal 10.2.1 fixes this bug. No patches to MinifyHTML are needed.

  • πŸ‡©πŸ‡ͺGermany sense-design MΓΌnster

    Seems that Drupal 10.2.1 fixes the issues. I could not find any errors anymore.

  • Status changed to Closed: works as designed 12 months ago
  • πŸ‡¨πŸ‡¦Canada slydevil Halifax

    Amazing, so the underlying issue was with Drupal core!

  • πŸ‡©πŸ‡ͺGermany zcht

    I can confirm, with Drupal 10.2.1 everything works perfectly without patch :)

Production build 0.71.5 2024