diff --git a/library/Icinga/Application/Modules/Manager.php b/library/Icinga/Application/Modules/Manager.php index 55d074d70..9114f3ad4 100644 --- a/library/Icinga/Application/Modules/Manager.php +++ b/library/Icinga/Application/Modules/Manager.php @@ -3,6 +3,7 @@ namespace Icinga\Application\Modules; +use Fiber; use Icinga\Application\ApplicationBootstrap; use Icinga\Application\Icinga; use Icinga\Application\Logger; @@ -187,8 +188,16 @@ class Manager public function loadEnabledModules() { if (! $this->loadedAllEnabledModules) { + $async = ! $this->app->isCli(); foreach ($this->listEnabledModules() as $name) { - $this->loadModule($name); + if ($async) { + // May be suspended during authentication and resumed upon finish + (new Fiber(function () use ($name) { + $this->loadModule($name); + }))->start(); + } else { + $this->loadModule($name); + } } $this->loadedAllEnabledModules = true; diff --git a/library/Icinga/Authentication/Auth.php b/library/Icinga/Authentication/Auth.php index c2fbbeb4f..ee4deac1c 100644 --- a/library/Icinga/Authentication/Auth.php +++ b/library/Icinga/Authentication/Auth.php @@ -4,6 +4,7 @@ namespace Icinga\Authentication; use Exception; +use Fiber; use Icinga\Application\Config; use Icinga\Application\Hook\AuditHook; use Icinga\Application\Icinga; @@ -59,6 +60,15 @@ class Auth */ private bool $authenticated = false; + /** + * Fibers that were suspended during authentication + * + * This is used to resume fibers after authentication has been performed. + * + * @var Fiber[] + */ + private array $suspendedFibers = []; + /** * @see getInstance() */ @@ -97,7 +107,13 @@ class Auth public function isAuthenticated() { if (! $this->authenticated) { - trigger_error('Authentication can no longer be triggered implicitly', E_USER_DEPRECATED); + $fiber = Fiber::getCurrent(); + if ($fiber !== null) { + $this->suspendedFibers[] = $fiber; + Fiber::suspend(); + } else { + trigger_error('Authentication can no longer be triggered implicitly', E_USER_DEPRECATED); + } } return $this->user !== null; @@ -250,6 +266,13 @@ class Auth $this->authenticated = true; + foreach ($this->suspendedFibers as $fiber) { + // Resume all suspended fibers + $fiber->resume(); + } + + $this->suspendedFibers = []; + return $this; }