Skip to content

Commit d16d32e

Browse files
Implement cache size management in version comparison to prevent unbounded growth
1 parent 0d235b3 commit d16d32e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

react_on_rails_pro/packages/node-renderer/src/worker/checkProtocolVersionHandler.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const NODE_ENV = process.env.NODE_ENV || 'production';
1111
// Cache to store version comparison results to avoid repeated normalization and logging
1212
// Key: gemVersion string, Value: boolean (true if matches, false if mismatch)
1313
// If key exists, it means we've already processed and logged this version (if needed)
14+
// Cache is cleared when it exceeds 10 entries to prevent unbounded growth
15+
const VERSION_CACHE_MAX_SIZE = 10;
1416
const versionCache = new Map<string, boolean>();
1517

1618
/**
@@ -67,6 +69,12 @@ Update either the renderer or the Rails server`,
6769
const normalizedGemVersion = normalizeVersion(gemVersion);
6870
const normalizedPackageVersion = normalizeVersion(packageJson.version);
6971
versionsMatch = normalizedGemVersion === normalizedPackageVersion;
72+
73+
// Clear cache if it exceeds max size to prevent unbounded growth
74+
if (versionCache.size >= VERSION_CACHE_MAX_SIZE) {
75+
versionCache.clear();
76+
}
77+
7078
versionCache.set(gemVersion, versionsMatch);
7179
justCached = true;
7280
}

0 commit comments

Comments
 (0)