aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorAndy Scherzinger <info@andy-scherzinger.de>2024-08-08 10:28:45 +0200
committerGitHub <noreply@github.com>2024-08-08 10:28:45 +0200
commitfe6e5fa6532cfc6f66e8dc5c5d89d228da41b35c (patch)
treef77fb2ac1ccc3f1791978f74a70f1f6d7aed54ec /lib/private
parentd2f1ea98ea7743291261b70dcbe63b0e47a5269b (diff)
parent0a0c07cec141a5590f407627c808691d5688ffa7 (diff)
downloadnextcloud-server-fe6e5fa6532cfc6f66e8dc5c5d89d228da41b35c.tar.gz
nextcloud-server-fe6e5fa6532cfc6f66e8dc5c5d89d228da41b35c.zip
Merge pull request #47105 from nextcloud/backport/46106/stable29
[stable29] fix(session): Log when session_* calls are slow
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Server.php2
-rw-r--r--lib/private/Session/Internal.php31
-rw-r--r--lib/private/Session/Memory.php5
-rw-r--r--lib/private/Session/Session.php7
4 files changed, 29 insertions, 16 deletions
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 3e7a7b51af1..ad1f188881a 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -532,7 +532,7 @@ class Server extends ServerContainer implements IServerContainer {
$this->registerService(\OC\User\Session::class, function (Server $c) {
$manager = $c->get(IUserManager::class);
- $session = new \OC\Session\Memory('');
+ $session = new \OC\Session\Memory();
$timeFactory = new TimeFactory();
// Token providers might require a working database. This code
// might however be called when Nextcloud is not yet setup.
diff --git a/lib/private/Session/Internal.php b/lib/private/Session/Internal.php
index bbc8ca83464..9002132e305 100644
--- a/lib/private/Session/Internal.php
+++ b/lib/private/Session/Internal.php
@@ -35,7 +35,11 @@ namespace OC\Session;
use OC\Authentication\Token\IProvider;
use OCP\Authentication\Exceptions\InvalidTokenException;
+use OCP\ILogger;
use OCP\Session\Exceptions\SessionNotAvailableException;
+use Psr\Log\LoggerInterface;
+use function call_user_func_array;
+use function microtime;
/**
* Class Internal
@@ -49,7 +53,8 @@ class Internal extends Session {
* @param string $name
* @throws \Exception
*/
- public function __construct(string $name) {
+ public function __construct(string $name,
+ private LoggerInterface $logger) {
set_error_handler([$this, 'trapError']);
$this->invoke('session_name', [$name]);
$this->invoke('session_cache_limiter', ['']);
@@ -208,11 +213,31 @@ class Internal extends Session {
*/
private function invoke(string $functionName, array $parameters = [], bool $silence = false) {
try {
+ $timeBefore = microtime(true);
if ($silence) {
- return @call_user_func_array($functionName, $parameters);
+ $result = @call_user_func_array($functionName, $parameters);
} else {
- return call_user_func_array($functionName, $parameters);
+ $result = call_user_func_array($functionName, $parameters);
}
+ $timeAfter = microtime(true);
+ $timeSpent = $timeAfter - $timeBefore;
+ if ($timeSpent > 0.1) {
+ $logLevel = match (true) {
+ $timeSpent > 25 => ILogger::ERROR,
+ $timeSpent > 10 => ILogger::WARN,
+ $timeSpent > 0.5 => ILogger::INFO,
+ default => ILogger::DEBUG,
+ };
+ $this->logger->log(
+ $logLevel,
+ "Slow session operation $functionName detected",
+ [
+ 'parameters' => $parameters,
+ 'timeSpent' => $timeSpent,
+ ],
+ );
+ }
+ return $result;
} catch (\Error $e) {
$this->trapError($e->getCode(), $e->getMessage());
}
diff --git a/lib/private/Session/Memory.php b/lib/private/Session/Memory.php
index fe71ec77692..a6cfa691d5d 100644
--- a/lib/private/Session/Memory.php
+++ b/lib/private/Session/Memory.php
@@ -42,11 +42,6 @@ use OCP\Session\Exceptions\SessionNotAvailableException;
class Memory extends Session {
protected $data;
- public function __construct(string $name) {
- //no need to use $name since all data is already scoped to this instance
- $this->data = [];
- }
-
/**
* @param string $key
* @param integer $value
diff --git a/lib/private/Session/Session.php b/lib/private/Session/Session.php
index 04fc61fe610..38d2706c133 100644
--- a/lib/private/Session/Session.php
+++ b/lib/private/Session/Session.php
@@ -39,13 +39,6 @@ abstract class Session implements \ArrayAccess, ISession {
protected $sessionClosed = false;
/**
- * $name serves as a namespace for the session keys
- *
- * @param string $name
- */
- abstract public function __construct(string $name);
-
- /**
* @param mixed $offset
* @return bool
*/