From b89873f82f831f5233d33d064785ce5c59e4fa63 Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Mon, 20 Apr 2020 09:38:45 -0300 Subject: [PATCH] [FIX] Web Client memory leak caused by the Emoji library (#17320) --- .../server/functions/hasPermission.js | 2 +- app/emoji-emojione/lib/rocketchat.js | 9 ++-- package-lock.json | 45 ++++++++++++++----- package.json | 2 +- 4 files changed, 42 insertions(+), 16 deletions(-) diff --git a/app/authorization/server/functions/hasPermission.js b/app/authorization/server/functions/hasPermission.js index 7077e0220c9e..141b16008b99 100644 --- a/app/authorization/server/functions/hasPermission.js +++ b/app/authorization/server/functions/hasPermission.js @@ -5,7 +5,7 @@ import { Permissions, Users, Subscriptions } from '../../../models/server/raw'; const rolesHasPermission = mem(async (permission, roles) => { const result = await Permissions.findOne({ _id: permission, roles: { $in: roles } }); return !!result; -}); +}, process.env.TEST_MODE === 'true' ? { maxAge: 0 } : undefined); const getRoles = mem(async (uid, scope) => { const { roles: userRoles = [] } = await Users.findOne({ _id: uid }); diff --git a/app/emoji-emojione/lib/rocketchat.js b/app/emoji-emojione/lib/rocketchat.js index b9e9aafb33b3..8632dcdd4fd3 100644 --- a/app/emoji-emojione/lib/rocketchat.js +++ b/app/emoji-emojione/lib/rocketchat.js @@ -167,8 +167,9 @@ emojione.emojioneList[':asterisk_symbol:'] = { // fix for :+1: - had to replace all function that does its conversion: https://github.com/joypixels/emojione/blob/4.5.0/lib/js/emojione.js#L249 (function(ns) { - ns.shortnameConversionMap = mem(ns.shortnameConversionMap); - ns.unicodeCharRegex = mem(ns.unicodeCharRegex); + ns.shortnameConversionMap = mem(ns.shortnameConversionMap, { maxAge: 1000 }); + + ns.unicodeCharRegex = mem(ns.unicodeCharRegex, { maxAge: 1000 }); const convertShortName = mem(function(shortname) { // the fix is basically adding this .replace(/[+]/g, '\\$&') @@ -202,7 +203,7 @@ emojione.emojioneList[':asterisk_symbol:'] = { return `${ alt }`; } return `${ alt }`; - }); + }, { maxAge: 1000 }); const convertUnicode = mem(function(entire, m1, m2, m3) { const mappedUnicode = ns.mapUnicodeToShort(); @@ -228,7 +229,7 @@ emojione.emojioneList[':asterisk_symbol:'] = { return `${ m2 }${ alt }`; } return `${ m2 }${ alt }`; - }); + }, { maxAge: 1000 }); ns.shortnameToImage = function(str) { // replace regular shortnames first diff --git a/package-lock.json b/package-lock.json index ef558ddb576c..b5e15c00e2ca 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3067,6 +3067,23 @@ "pseudomap": "^1.0.2", "yallist": "^2.1.2" } + }, + "mem": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/mem/-/mem-4.3.0.tgz", + "integrity": "sha512-qX2bG48pTqYRVmDB37rn/6PT7LcR8T7oAX3bf99u1Tt1nzxYfxkgqDwUwolPlXweM0XzBOBFzSx4kfp7KP1s/w==", + "dev": true, + "requires": { + "map-age-cleaner": "^0.1.1", + "mimic-fn": "^2.0.0", + "p-is-promise": "^2.0.0" + } + }, + "mimic-fn": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", + "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", + "dev": true } } }, @@ -20648,13 +20665,19 @@ "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=" }, "mem": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/mem/-/mem-4.1.0.tgz", - "integrity": "sha512-I5u6Q1x7wxO0kdOpYBB28xueHADYps5uty/zg936CiG8NTe5sJL8EjrCuLneuDW3PlMdZBGDIn8BirEVdovZvg==", + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/mem/-/mem-6.1.0.tgz", + "integrity": "sha512-RlbnLQgRHk5lwqTtpEkBTQ2ll/CG/iB+J4Hy2Wh97PjgZgXgWJWrFF+XXujh3UUVLvR4OOTgZzcWMMwnehlEUg==", "requires": { - "map-age-cleaner": "^0.1.1", - "mimic-fn": "^1.0.0", - "p-is-promise": "^2.0.0" + "map-age-cleaner": "^0.1.3", + "mimic-fn": "^3.0.0" + }, + "dependencies": { + "mimic-fn": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-3.0.0.tgz", + "integrity": "sha512-PiVO95TKvhiwgSwg1IdLYlCTdul38yZxZMIcnDSFIBUm4BNZha2qpQ4GpJ++15bHoKDtrW2D69lMfFwdFYtNZQ==" + } } }, "memoize-one": { @@ -21688,7 +21711,8 @@ "mimic-fn": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.2.0.tgz", - "integrity": "sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==" + "integrity": "sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==", + "dev": true }, "mimic-response": { "version": "1.0.1", @@ -23258,9 +23282,10 @@ "dev": true }, "p-is-promise": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/p-is-promise/-/p-is-promise-2.0.0.tgz", - "integrity": "sha512-pzQPhYMCAgLAKPWD2jC3Se9fEfrD9npNos0y150EeqZll7akhEgGhTW/slB6lHku8AvYGiJ+YJ5hfHKePPgFWg==" + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/p-is-promise/-/p-is-promise-2.1.0.tgz", + "integrity": "sha512-Y3W0wlRPK8ZMRbNq97l4M5otioeA5lm1z7bkNkxCka8HSPjR0xRWmpCmc9utiaLP9Jb1eD8BgeIxTW4AIF45Pg==", + "dev": true }, "p-limit": { "version": "2.0.0", diff --git a/package.json b/package.json index 56e3a8874222..4164ff98e039 100644 --- a/package.json +++ b/package.json @@ -194,7 +194,7 @@ "lru-cache": "^5.1.1", "mailparser": "^2.4.3", "marked": "^0.6.1", - "mem": "4.1.0", + "mem": "^6.1.0", "meteor-node-stubs": "^1.0.0", "mime-db": "^1.40.0", "mime-type": "^3.0.7",