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

[stable24] Don't spam the log with fatals when maintenance mode is enabled or an… #32858

Merged
merged 1 commit into from
Jun 28, 2022
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
1 change: 1 addition & 0 deletions apps/dav/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@
'OCA\\DAV\\Events\\SubscriptionCreatedEvent' => $baseDir . '/../lib/Events/SubscriptionCreatedEvent.php',
'OCA\\DAV\\Events\\SubscriptionDeletedEvent' => $baseDir . '/../lib/Events/SubscriptionDeletedEvent.php',
'OCA\\DAV\\Events\\SubscriptionUpdatedEvent' => $baseDir . '/../lib/Events/SubscriptionUpdatedEvent.php',
'OCA\\DAV\\Exception\\ServerMaintenanceMode' => $baseDir . '/../lib/Exception/ServerMaintenanceMode.php',
'OCA\\DAV\\Exception\\UnsupportedLimitOnInitialSyncException' => $baseDir . '/../lib/Exception/UnsupportedLimitOnInitialSyncException.php',
'OCA\\DAV\\Files\\BrowserErrorPagePlugin' => $baseDir . '/../lib/Files/BrowserErrorPagePlugin.php',
'OCA\\DAV\\Files\\FileSearchBackend' => $baseDir . '/../lib/Files/FileSearchBackend.php',
Expand Down
1 change: 1 addition & 0 deletions apps/dav/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ class ComposerStaticInitDAV
'OCA\\DAV\\Events\\SubscriptionCreatedEvent' => __DIR__ . '/..' . '/../lib/Events/SubscriptionCreatedEvent.php',
'OCA\\DAV\\Events\\SubscriptionDeletedEvent' => __DIR__ . '/..' . '/../lib/Events/SubscriptionDeletedEvent.php',
'OCA\\DAV\\Events\\SubscriptionUpdatedEvent' => __DIR__ . '/..' . '/../lib/Events/SubscriptionUpdatedEvent.php',
'OCA\\DAV\\Exception\\ServerMaintenanceMode' => __DIR__ . '/..' . '/../lib/Exception/ServerMaintenanceMode.php',
'OCA\\DAV\\Exception\\UnsupportedLimitOnInitialSyncException' => __DIR__ . '/..' . '/../lib/Exception/UnsupportedLimitOnInitialSyncException.php',
'OCA\\DAV\\Files\\BrowserErrorPagePlugin' => __DIR__ . '/..' . '/../lib/Files/BrowserErrorPagePlugin.php',
'OCA\\DAV\\Files\\FileSearchBackend' => __DIR__ . '/..' . '/../lib/Files/FileSearchBackend.php',
Expand Down
9 changes: 3 additions & 6 deletions apps/dav/lib/Connector/Sabre/ExceptionLoggerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

use OCA\DAV\Connector\Sabre\Exception\FileLocked;
use OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden;
use OCA\DAV\Exception\ServerMaintenanceMode;
use OCP\Files\StorageNotAvailableException;
use OCP\ILogger;
use Sabre\DAV\Exception\BadRequest;
Expand Down Expand Up @@ -81,6 +82,7 @@ class ExceptionLoggerPlugin extends \Sabre\DAV\ServerPlugin {
FileLocked::class => true,
// An invalid range is requested
RequestedRangeNotSatisfiable::class => true,
ServerMaintenanceMode::class => true,
];

/** @var string */
Expand Down Expand Up @@ -120,12 +122,7 @@ public function initialize(\Sabre\DAV\Server $server) {
public function logException(\Throwable $ex) {
$exceptionClass = get_class($ex);
$level = ILogger::FATAL;
if (isset($this->nonFatalExceptions[$exceptionClass]) ||
(
$exceptionClass === ServiceUnavailable::class &&
$ex->getMessage() === 'System in maintenance mode.'
)
) {
if (isset($this->nonFatalExceptions[$exceptionClass])) {
$level = ILogger::DEBUG;
}

Expand Down
5 changes: 3 additions & 2 deletions apps/dav/lib/Connector/Sabre/MaintenancePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/
namespace OCA\DAV\Connector\Sabre;

use OCA\DAV\Exception\ServerMaintenanceMode;
use OCP\IConfig;
use OCP\IL10N;
use OCP\Util;
Expand Down Expand Up @@ -82,10 +83,10 @@ public function initialize(\Sabre\DAV\Server $server) {
*/
public function checkMaintenanceMode() {
if ($this->config->getSystemValueBool('maintenance')) {
throw new ServiceUnavailable($this->l10n->t('System is in maintenance mode.'));
throw new ServerMaintenanceMode($this->l10n->t('System is in maintenance mode.'));
}
if (Util::needUpgrade()) {
throw new ServiceUnavailable($this->l10n->t('Upgrade needed'));
throw new ServerMaintenanceMode($this->l10n->t('Upgrade needed'));
}

return true;
Expand Down
31 changes: 31 additions & 0 deletions apps/dav/lib/Exception/ServerMaintenanceMode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2022 Joas Schilling <coding@schilljs.com>
*
* @author Joas Schilling <coding@schilljs.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\DAV\Exception;

use Sabre\DAV\Exception\ServiceUnavailable;

class ServerMaintenanceMode extends ServiceUnavailable {

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
use OC\SystemConfig;
use OCA\DAV\Connector\Sabre\Exception\InvalidPath;
use OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin as PluginToTest;
use OCA\DAV\Exception\ServerMaintenanceMode;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\Exception\ServiceUnavailable;
use Sabre\DAV\Server;
use Test\TestCase;

Expand Down Expand Up @@ -91,8 +91,8 @@ public function testLogging($expectedLogLevel, $expectedMessage, $exception) {
public function providesExceptions() {
return [
[0, '', new NotFound()],
[0, 'System in maintenance mode.', new ServiceUnavailable('System in maintenance mode.')],
[4, 'Upgrade needed', new ServiceUnavailable('Upgrade needed')],
[0, 'System in maintenance mode.', new ServerMaintenanceMode('System in maintenance mode.')],
[0, 'Upgrade needed', new ServerMaintenanceMode('Upgrade needed')],
[4, 'This path leads to nowhere', new InvalidPath('This path leads to nowhere')]
];
}
Expand Down