Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid db connections when logging db connection errors #37458

Merged
merged 2 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@
*
*/
require_once __DIR__ . '/lib/versioncheck.php';
use Psr\Log\LoggerInterface;

try {
require_once __DIR__ . '/lib/base.php';

OC::handleRequest();
} catch (\OC\ServiceUnavailableException $ex) {
\OC::$server->getLogger()->logException($ex, ['app' => 'index']);
\OC::$server->get(LoggerInterface::class)->error($ex->getMessage(), [
'app' => 'index',
'exception' => $ex,
]);

//show the user a detailed error page
OC_Template::printExceptionErrorPage($ex, 503);
Expand All @@ -44,8 +48,14 @@
OC_Template::printErrorPage($ex->getMessage(), $ex->getHint(), 503);
} catch (Exception $ex2) {
try {
\OC::$server->getLogger()->logException($ex, ['app' => 'index']);
\OC::$server->getLogger()->logException($ex2, ['app' => 'index']);
\OC::$server->get(LoggerInterface::class)->error($ex->getMessage(), [
'app' => 'index',
'exception' => $ex,
]);
\OC::$server->get(LoggerInterface::class)->error($ex2->getMessage(), [
'app' => 'index',
'exception' => $ex2,
]);
} catch (Throwable $e) {
// no way to log it properly - but to avoid a white page of death we try harder and ignore this one here
}
Expand All @@ -68,13 +78,19 @@
}
OC_Template::printErrorPage($ex->getMessage(), $ex->getMessage(), 401);
} catch (Exception $ex) {
\OC::$server->getLogger()->logException($ex, ['app' => 'index']);
\OC::$server->get(LoggerInterface::class)->error($ex->getMessage(), [
'app' => 'index',
'exception' => $ex,
]);

//show the user a detailed error page
OC_Template::printExceptionErrorPage($ex, 500);
} catch (Error $ex) {
try {
\OC::$server->getLogger()->logException($ex, ['app' => 'index']);
\OC::$server->get(LoggerInterface::class)->error($ex->getMessage(), [
'app' => 'index',
'exception' => $ex,
]);
} catch (Error $e) {
http_response_code(500);
header('Content-Type: text/plain; charset=utf-8');
Expand Down
8 changes: 7 additions & 1 deletion lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,13 @@ public function __construct($webRoot, \OC\Config $config) {

if ($config->getSystemValueBool('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
if (!$config->getSystemValueBool('log_query')) {
$v = \OC_App::getAppVersions();
try {
$v = \OC_App::getAppVersions();
} catch (\Doctrine\DBAL\Exception $e) {
come-nc marked this conversation as resolved.
Show resolved Hide resolved
// Database service probably unavailable
// Probably related to https://github.com/nextcloud/server/issues/37424
return $arrayCacheFactory;
}
} else {
// If the log_query is enabled, we can not get the app versions
// as that does a query, which will be logged and the logging
Expand Down