From d8b1dfaa416397bb13057d49bc752a1172bc1f71 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Fri, 15 Oct 2021 14:15:47 -0400 Subject: [PATCH] Increase max size limit for single file syncs Signed-off-by: Sebastian Malton --- src/main/catalog-sources/kubeconfig-sync.ts | 29 ++++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/main/catalog-sources/kubeconfig-sync.ts b/src/main/catalog-sources/kubeconfig-sync.ts index 748eb129bd..14d7bef128 100644 --- a/src/main/catalog-sources/kubeconfig-sync.ts +++ b/src/main/catalog-sources/kubeconfig-sync.ts @@ -60,7 +60,8 @@ const ignoreGlobs = [ * Even if you have a cert-file, key-file, and client-cert files that is only * 12kb of extra data (at 4096 bytes each) which allows for around 150 entries. */ -const maxAllowedFileReadSize = 2 * 1024 * 1024; // 2 MiB +const folderSyncMaxAllowedFileReadSize = 2 * 1024 * 1024; // 2 MiB +const fileSyncMaxAllowedFileReadSize = 16 * folderSyncMaxAllowedFileReadSize; // 32 MiB export class KubeconfigSyncManager extends Singleton { protected sources = observable.map, Disposer]>(); @@ -236,7 +237,14 @@ export function computeDiff(contents: string, source: RootSource, filePath: stri }); } -function diffChangedConfig(filePath: string, source: RootSource, stats: fs.Stats): Disposer { +interface DiffChangedConfigArgs { + filePath: string; + source: RootSource; + stats: fs.Stats; + maxAllowedFileReadSize: number; +} + +function diffChangedConfig({ filePath, source, stats, maxAllowedFileReadSize }: DiffChangedConfigArgs): Disposer { logger.debug(`${logPrefix} file changed`, { filePath }); if (stats.size >= maxAllowedFileReadSize) { @@ -303,6 +311,9 @@ function watchFileChanges(filePath: string): [IComputedValue, D const stat = await fs.promises.stat(filePath); const isFolderSync = stat.isDirectory(); const cleanupFns = new Map(); + const maxAllowedFileReadSize = isFolderSync + ? folderSyncMaxAllowedFileReadSize + : fileSyncMaxAllowedFileReadSize; watcher = watch(filePath, { followSymlinks: true, @@ -327,7 +338,12 @@ function watchFileChanges(filePath: string): [IComputedValue, D } cleanup(); - cleanupFns.set(childFilePath, diffChangedConfig(childFilePath, rootSource.getOrInsert(childFilePath, observable.map), stats)); + cleanupFns.set(childFilePath, diffChangedConfig({ + filePath: childFilePath, + source: rootSource.getOrInsert(childFilePath, observable.map), + stats, + maxAllowedFileReadSize, + })); }) .on("add", (childFilePath, stats) => { if (isFolderSync) { @@ -340,7 +356,12 @@ function watchFileChanges(filePath: string): [IComputedValue, D } } - cleanupFns.set(childFilePath, diffChangedConfig(childFilePath, rootSource.getOrInsert(childFilePath, observable.map), stats)); + cleanupFns.set(childFilePath, diffChangedConfig({ + filePath: childFilePath, + source: rootSource.getOrInsert(childFilePath, observable.map), + stats, + maxAllowedFileReadSize, + })); }) .on("unlink", (childFilePath) => { cleanupFns.get(childFilePath)?.();