aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Steinmetz <richard@steinmetz.cloud>2024-08-05 09:06:53 +0200
committerGitHub <noreply@github.com>2024-08-05 09:06:53 +0200
commit8511b89579b761798ea4f6ecf9257cad8d0bc462 (patch)
tree4e1bb94316d459010f8366ea4f5eee72e72dde7e
parentc283683a08a6aefb60997e961d1365c61e4d0100 (diff)
parent2ea6713504aa49d1a8cb9a7efaad8706484986c1 (diff)
downloadnextcloud-server-8511b89579b761798ea4f6ecf9257cad8d0bc462.tar.gz
nextcloud-server-8511b89579b761798ea4f6ecf9257cad8d0bc462.zip
Merge pull request #42800 from nextcloud/metaGenMemLimit
enh(metadata): Introduce a memory limit for metadata generation
-rw-r--r--config/config.sample.php9
-rw-r--r--core/BackgroundJobs/GenerateMetadataJob.php14
2 files changed, 23 insertions, 0 deletions
diff --git a/config/config.sample.php b/config/config.sample.php
index 8b3c9feae45..f2d06d9acea 100644
--- a/config/config.sample.php
+++ b/config/config.sample.php
@@ -1374,6 +1374,15 @@ $CONFIG = [
],
/**
+ * Maximum file size for metadata generation.
+ * If a file exceeds this size, metadata generation will be skipped.
+ * Note: memory equivalent to this size will be used for metadata generation.
+ *
+ * Default: 256 megabytes.
+ */
+'metadata_max_filesize' => 256,
+
+/**
* LDAP
*
* Global settings used by LDAP User and Group Backend
diff --git a/core/BackgroundJobs/GenerateMetadataJob.php b/core/BackgroundJobs/GenerateMetadataJob.php
index 809e139e6ef..c40a1b11f06 100644
--- a/core/BackgroundJobs/GenerateMetadataJob.php
+++ b/core/BackgroundJobs/GenerateMetadataJob.php
@@ -16,12 +16,17 @@ use OCP\Files\IRootFolder;
use OCP\FilesMetadata\Exceptions\FilesMetadataNotFoundException;
use OCP\FilesMetadata\IFilesMetadataManager;
use OCP\IAppConfig;
+use OCP\IConfig;
use OCP\IUserManager;
use Psr\Log\LoggerInterface;
class GenerateMetadataJob extends TimedJob {
+ // Default file size limit for metadata generation (MBytes).
+ protected const DEFAULT_MAX_FILESIZE = 256;
+
public function __construct(
ITimeFactory $time,
+ private IConfig $config,
private IAppConfig $appConfig,
private IRootFolder $rootFolder,
private IUserManager $userManager,
@@ -88,6 +93,15 @@ class GenerateMetadataJob extends TimedJob {
continue;
}
+ // Don't generate metadata for files bigger than configured metadata_max_filesize
+ // Files are loaded in memory so very big files can lead to an OOM on the server
+ $nodeSize = $node->getSize();
+ $nodeLimit = $this->config->getSystemValueInt('metadata_max_filesize', self::DEFAULT_MAX_FILESIZE);
+ if ($nodeSize > $nodeLimit * 1000000) {
+ $this->logger->debug("Skipping generating metadata for fileid " . $node->getId() . " as its size exceeds configured 'metadata_max_filesize'.");
+ continue;
+ }
+
try {
$this->filesMetadataManager->getMetadata($node->getId(), false);
} catch (FilesMetadataNotFoundException) {