TypeError: Argument 1 passed to Drupal\Core\Session\SessionConfiguration::getOptions() must be an instance of Symfony\Component\HttpFoundation\Request, null given, called in /var/www/drupal_8/web/core/lib/Drupal/Core/Session/SessionManager.php on line 111 в Drupal\Core\Session\SessionConfiguration->getOptions() (строка 40 из /var/www/drupal_8/web/core/lib/Drupal/Core/Session/SessionConfiguration.php)
#0 /var/www/drupal_8/web/core/lib/Drupal/Core/Session/SessionManager.php(111): Drupal\Core\Session\SessionConfiguration->getOptions(NULL)
#1 /var/www/drupal_8/vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php(299): Drupal\Core\Session\SessionManager->start()
#2 /var/www/drupal_8/vendor/symfony/http-foundation/Session/Session.php(256): Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage->getBag('attributes')
#3 /var/www/drupal_8/vendor/symfony/http-foundation/Session/Session.php(280): Symfony\Component\HttpFoundation\Session\Session->getBag('attributes')
#4 /var/www/drupal_8/vendor/symfony/http-foundation/Session/Session.php(73): Symfony\Component\HttpFoundation\Session\Session->getAttributeBag()
#5 /var/www/drupal_8/web/modules/contrib/smart_ip/src/SmartIp.php(167): Symfony\Component\HttpFoundation\Session\Session->get('smart_ip')
#6 /var/www/drupal_8/web/modules/contrib/smart_ip/src/SmartIpLocation.php(181): Drupal\smart_ip\SmartIp::getSession('smart_ip')
#7 /var/www/drupal_8/web/modules/contrib/smart_ip/src/SmartIpLocation.php(148): Drupal\smart_ip\SmartIpLocation->getData(false)
#8 /var/www/drupal_8/web/core/lib/Drupal/Component/DependencyInjection/Container.php(265): Drupal\smart_ip\SmartIpLocation->__construct()
#9 /var/www/drupal_8/web/core/lib/Drupal/Component/DependencyInjection/Container.php(173): Drupal\Component\DependencyInjection\Container->createService(Array, 'smart_ip.smart_...')
#10 /var/www/drupal_8/web/modules/contrib/devel/webprofiler/src/DependencyInjection/TraceableContainer.php(50): Drupal\Component\DependencyInjection\Container->get('smart_ip.smart_...', 1)
#11 /var/www/drupal_8/web/core/lib/Drupal/Component/DependencyInjection/Container.php(487): Drupal\webprofiler\DependencyInjection\TraceableContainer->get('smart_ip.smart_...', 1)
#12 /var/www/drupal_8/web/core/lib/Drupal/Component/DependencyInjection/Container.php(237): Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array)
#13 /var/www/drupal_8/web/core/lib/Drupal/Component/DependencyInjection/Container.php(173): Drupal\Component\DependencyInjection\Container->createService(Array, 'rg_location.reg...')
#14 /var/www/drupal_8/web/modules/contrib/devel/webprofiler/src/DependencyInjection/TraceableContainer.php(50): Drupal\Component\DependencyInjection\Container->get('rg_location.reg...', 1)
#15 /var/www/drupal_8/web/core/lib/Drupal/Component/DependencyInjection/Container.php(487): Drupal\webprofiler\DependencyInjection\TraceableContainer->get('rg_location.reg...', 1)
#16 /var/www/drupal_8/web/core/lib/Drupal/Component/DependencyInjection/Container.php(237): Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array)
#17 /var/www/drupal_8/web/core/lib/Drupal/Component/DependencyInjection/Container.php(173): Drupal\Component\DependencyInjection\Container->createService(Array, 'rg_location.fac...')
#18 /var/www/drupal_8/web/modules/contrib/devel/webprofiler/src/DependencyInjection/TraceableContainer.php(50): Drupal\Component\DependencyInjection\Container->get('rg_location.fac...', 1)
#19 /var/www/drupal_8/web/core/lib/Drupal.php(158): Drupal\webprofiler\DependencyInjection\TraceableContainer->get('rg_location.fac...')
#20 /var/www/drupal_8/web/modules/custom/rg_location/src/RedirectToCityMiddleware.php(34): Drupal::service('rg_location.fac...')
#21 /var/www/drupal_8/web/core/lib/Drupal/Component/DependencyInjection/Container.php(269): Drupal\rg_location\RedirectToCityMiddleware->__construct(Object(Drupal\Core\StackMiddleware\NegotiationMiddleware))
#22 /var/www/drupal_8/web/core/lib/Drupal/Component/DependencyInjection/Container.php(173): Drupal\Component\DependencyInjection\Container->createService(Array, 'rg_location.mid...')
#23 /var/www/drupal_8/web/modules/contrib/devel/webprofiler/src/DependencyInjection/TraceableContainer.php(50): Drupal\Component\DependencyInjection\Container->get('rg_location.mid...', 1)
#24 /var/www/drupal_8/web/core/lib/Drupal/Component/DependencyInjection/Container.php(487): Drupal\webprofiler\DependencyInjection\TraceableContainer->get('rg_location.mid...', 1)
#25 /var/www/drupal_8/web/core/lib/Drupal/Component/DependencyInjection/Container.php(237): Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array)
#26 /var/www/drupal_8/web/core/lib/Drupal/Component/DependencyInjection/Container.php(173): Drupal\Component\DependencyInjection\Container->createService(Array, 'http_kernel')
#27 /var/www/drupal_8/web/modules/contrib/devel/webprofiler/src/DependencyInjection/TraceableContainer.php(50): Drupal\Component\DependencyInjection\Container->get('http_kernel', 1)
#28 /var/www/drupal_8/web/core/lib/Drupal/Core/DrupalKernel.php(1387): Drupal\webprofiler\DependencyInjection\TraceableContainer->get('http_kernel')
#29 /var/www/drupal_8/web/core/lib/Drupal/Core/DrupalKernel.php(694): Drupal\Core\DrupalKernel->getHttpKernel()
#30 /var/www/drupal_8/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#31 {main}.

It is because sometimes

      /** @var \Symfony\Component\HttpFoundation\Session\Session $session */
      $session = \Drupal::service('session');
      $smartIpSession = $session->get($key);

could be executed before session started.

Patch will be attached.

Comments

super_romeo created an issue. See original summary.

super_romeo’s picture

super_romeo’s picture

Status: Active » Needs review
birdsnbees’s picture

Status: Needs review » Postponed (maintainer needs more info)

Please provide more details on how to replicate this issue. Please review this guideline:
https://www.drupal.org/node/73179#issue_summary.

super_romeo’s picture

I use this service from Middleware (https://www.drupal.org/docs/8/api/middleware-api/overview)

class MyMiddleware implements HttpKernelInterface {

  /**
   * {@inheritdoc}
   */
  public function handle(...) {
     // service called here.
  }

}

OthmanEmad’s picture

Version: 8.x-3.x-dev » 8.x-4.x-dev
Assigned: super_romeo » OthmanEmad
Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new641 bytes

Rerolled the patch to work on the latest version.
The issue lies when using a Middleware that has a higher priority than the http_middleware.session in the core (>50), the session won't be initialized yet so it causes errors.
So by checking if the session has started, we can either return the session or the default one, avoiding any errors.

  • arpeggio committed ef979b4 on 8.x-3.x
    Issue #3090575 by OthmanEmad: Check if session is started
    
arpeggio’s picture

Status: Needs review » Fixed

I have already pushed the patch. Thank you for sharing it @OthmanEmad.

Status: Fixed » Closed (fixed)

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