From b76b5f942407212a980d8707f27399fdbc081092 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 18 Oct 2024 17:35:39 +0200 Subject: [PATCH] debug: collect message on a SessionNotAvailableException case Signed-off-by: Arthur Schiwon --- lib/base.php | 2 ++ lib/private/App/AppManager.php | 8 ++++++++ lib/private/legacy/OC_User.php | 9 ++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/base.php b/lib/base.php index 115e7b11daf27..980e486b54e3f 100644 --- a/lib/base.php +++ b/lib/base.php @@ -447,6 +447,8 @@ public static function initSession(): void { $cryptoWrapper = Server::get(\OC\Session\CryptoWrapper::class); $session = $cryptoWrapper->wrapSession($session); + $e = new \Exception('Stacktrace for initializing Internal/Encrypted session'); + \OCP\Log\logger('core')->warning('SnaeDebug: Updating UserSession with persistent Internal/Encrypted backend', [ 'exception' => $e ]); self::$server->setSession($session); // if session can't be started break with http 500 error diff --git a/lib/private/App/AppManager.php b/lib/private/App/AppManager.php index 60e55a314d6cf..e182314c50d89 100644 --- a/lib/private/App/AppManager.php +++ b/lib/private/App/AppManager.php @@ -42,6 +42,7 @@ use OC\AppConfig; use OC\AppFramework\Bootstrap\Coordinator; use OC\ServerNotAvailableException; +use OC\Session\CryptoSessionData; use OCP\Activity\IManager as IActivityManager; use OCP\App\AppPathNotFoundException; use OCP\App\Events\AppDisableEvent; @@ -210,6 +211,13 @@ public function loadApps(array $types = []): bool { foreach ($apps as $app) { if (!$this->isAppLoaded($app) && ($types === [] || $this->isType($app, $types))) { try { + if (in_array('session', $types, true)) { + $e = new \Exception('Stacktrace for loading session-type app'); + \OCP\Log\logger('core')->warning('SnaeDebug: Loading session app ' . $app, [ 'exception' => $e ]); + } else if (method_exists($this->userSession, 'getSession') && !$this->userSession->getSession() instanceof CryptoSessionData) { + $e = new \Exception('Stacktrace for early loading of non session-type app'); + \OCP\Log\logger('core')->warning('SnaeDebug: Loading app early: ' . $app, [ 'exception' => $e, 'session' => get_class($this->userSession->getSession()) ]); + } $this->loadApp($app); } catch (\Throwable $e) { $this->logger->emergency('Error during app loading: ' . $e->getMessage(), [ diff --git a/lib/private/legacy/OC_User.php b/lib/private/legacy/OC_User.php index 9fd4e502fb4bb..dbb2cec6138be 100644 --- a/lib/private/legacy/OC_User.php +++ b/lib/private/legacy/OC_User.php @@ -210,9 +210,14 @@ public static function loginWithApache(\OCP\Authentication\IApacheBackend $backe 'filesystem' => true, ]); $tokenProvider->updateToken($token); - } catch (InvalidTokenException|WipeTokenException|SessionNotAvailableException) { + } catch (InvalidTokenException|WipeTokenException|SessionNotAvailableException $e) { // swallow the exceptions as we do not deal with them here // simply skip updating the token when is it missing + \OCP\Log\logger('core')->warning('SnaeDebug: Potential error case', [ + 'uid' => $uid, + 'session_class' => get_class($userSession->getSession()), + 'exception' => $e, + ]); } } @@ -255,6 +260,8 @@ public static function loginWithApache(\OCP\Authentication\IApacheBackend $backe * null: not handled / no backend available */ public static function handleApacheAuth() { + $e = new \Exception('Stacktrace for invoking apache auth'); + \OCP\Log\logger('core')->warning('SnaeDebug: ApacheAuth was invoked', [ 'exception' => $e ]); $backend = self::findFirstActiveUsedBackend(); if ($backend) { OC_App::loadApps();