Created on 5 August 2023, about 1 year ago
Updated 14 November 2023, 11 months ago

Problem/Motivation

I installed this module this week in 10 D9.5.10 sites. Now i get daily several php erors:

TypeError: Drupal\Core\Routing\RequestContext::fromRequest(): Argument #1 ($request) must be of type Symfony\Component\HttpFoundation\Request, null given, called in /.../core/lib/Drupal/Core/Routing/RequestContext.php on line 28 in Drupal\Core\Routing\RequestContext->fromRequest() (line 34 of /.../core/lib/Drupal/Core/Routing/RequestContext.php)

#0 /.../core/lib/Drupal/Core/Routing/RequestContext.php(28): Drupal\Core\Routing\RequestContext->fromRequest()
#1 [internal function]: Drupal\Core\Routing\RequestContext->fromRequestStack()
#2 /.../core/lib/Drupal/Component/DependencyInjection/Container.php(276): call_user_func_array()
#3 /.../core/lib/Drupal/Component/DependencyInjection/Container.php(177): Drupal\Component\DependencyInjection\Container->createService()
#4 /.../core/lib/Drupal/Component/DependencyInjection/Container.php(434): Drupal\Component\DependencyInjection\Container->get()
#5 /.../core/lib/Drupal/Component/DependencyInjection/Container.php(273): Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters()
#6 /.../core/lib/Drupal/Component/DependencyInjection/Container.php(449): Drupal\Component\DependencyInjection\Container->createService()
#7 /.../core/lib/Drupal/Component/DependencyInjection/Container.php(237): Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters()
#8 /.../core/lib/Drupal/Component/DependencyInjection/Container.php(177): Drupal\Component\DependencyInjection\Container->createService()
#9 /.../core/lib/Drupal/Component/DependencyInjection/Container.php(434): Drupal\Component\DependencyInjection\Container->get()
#10 /.../core/lib/Drupal/Component/DependencyInjection/Container.php(237): Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters()
#11 /.../core/lib/Drupal/Component/DependencyInjection/Container.php(177): Drupal\Component\DependencyInjection\Container->createService()
#12 /.../core/lib/Drupal.php(207): Drupal\Component\DependencyInjection\Container->get()
#13 /.../core/lib/Drupal/Core/Link.php(186): Drupal::service()
#14 /.../core/lib/Drupal/Core/Link.php(164): Drupal\Core\Link->getLinkGenerator()
#15 /.../modules/contrib/crowdsec/src/Middleware.php(77): Drupal\Core\Link->toString()
#16 /.../core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\crowdsec\Middleware->handle()
#17 /.../core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#18 /.../vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#19 /.../core/lib/Drupal/Core/DrupalKernel.php(718): Stack\StackedHttpKernel->handle()
#20 /.../index.php(19): Drupal\Core\DrupalKernel->handle()
#21 {main}

Example from the log:
52.177.114.234 - - [05/Aug/2023:05:13:15 +0200] "GET /wp-includes/id3/license.txt/feed/ HTTP/1.1" 500 4727 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇳🇱Netherlands promes

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

Comments & Activities

  • Issue created by @promes
  • 🇩🇪Germany jurgenhaas Gottmadingen

    Thanks @PROMES for reporting this. Unfortunately, I can't reproduce this and from your stack trace it looks like for some reason, Drupal core doesn't receive the current request in \Drupal\Core\Routing\RequestContext::fromRequestStack:

      public function fromRequestStack(RequestStack $request_stack) {
        $this->fromRequest($request_stack->getCurrentRequest());
      }
    

    The only thing that looks strange to me, is in line 20 of the stack trace:

    # In the example above:
    index.php(19): Drupal\Core\DrupalKernel->handle()
    
    # In other cases, that I susually see:
    index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
    

    That looks as if normally, calling Kernal->handle gets a request object handed over. But in the case above, nothing is being handed over. As if the index.php file is broken or something else is preventing that file from receiving Request::createFromGlobals() in line 18 of that file. Could you probably debug that?

    Also, is that an installation that's being done with or without composer?

  • 🇳🇱Netherlands promes

    @jurgenhaas. Thanks for your quick reply. I use composer to install my sites and modules.
    As far as I can see, all TypeErrors occur when a bot(?) comes from an IP-address which is on a blacklist. Most of these IP-addesses are allready banned. I don't know how to debug such an event. But all blacklisted IPs give this error.

  • Status changed to Needs review about 1 year ago
  • 🇩🇪Germany jurgenhaas Gottmadingen

    comes from an IP-address which is on a blacklist

    That's an interesting detail. It helped me to find out, that our logging mechanism is called too early where some of the service are not always available yet. I could have lowered the priority of the CrowdSec middleware to check for blocked IPs later, but that would be less secure. So, I decided to change to logging content so that we don't require those missing services.

    Please give the latest dev release a try, if that fixes the issue for you as well.

  • 🇳🇱Netherlands promes

    Thanks. Now I get in 1 site 'Blocked' messages. I will continue to monitor the log messages and report later this week if any TypeError messages occur.

  • 🇳🇱Netherlands promes

    No more TypeErrors found. The blocking is now reported in the log, but the IPs are not banned.

  • Status changed to Fixed 12 months ago
  • 🇩🇪Germany jurgenhaas Gottmadingen

    Marking as fixed. If the last comment indicates an additional problem, please start a new issue with instructions on how to reproduce the issue.

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

  • Status changed to Fixed 11 months ago
  • 🇩🇪Germany Martin Mayer Germany and Philippines

    I tried the current dev version as suggested in #5, because I got the same error.
    Whenever I use a drush command like drus cr or drush updb I get this error message:

    PHP Fatal error: Declaration of Consolidation\Log\Logger::log($level, Stringable|string $message, array $context = []): void must be compatible with Psr\Log\LoggerInterface::log($level, $message, array $context = []) in /home/deploy/famplus-2023/vendor/consolidation/log/src/Logger.php on line 146

  • 🇩🇪Germany jurgenhaas Gottmadingen

    Hi @Martin Mayer as this is a closed issue, it's not a good idea to ask additional questions here. Also, it doesn't seem to be related to this issue at all, so that would always require a new on.

    But from what you're posting, I don't see how this is related to the CrowdSec module. It says that the declaration log($level, Stringable|string $message, array $context = []): void is not compatible, but that declaration doesn't exist in this module. Or am I missing something? If so, please provide all the necessary details in a new issue.

Production build 0.71.5 2024