small memory leak for plugin.setTimeout
Massimo Melina committed
May 1, 2026 at 00:38 UTC
d7b0902aaa7ee2bea31f8199d3995a612e5a0eae
1 file changed
+11
-3
src/plugins.ts
+11
-3
@@ -168,8 +168,16 @@ async function initPlugin(pl: any, morePassedToInit?: { id: string } & Dict) {
168
timeouts.push(ret) // intervals can be canceled by clearTimeout (source: MDN)
169
return ret
170
},
171
- setTimeout() { // @ts-ignore
172
- const ret = setTimeout(...arguments)
171
+ setTimeout(cb: (...args: any[]) => any, delay=0, ...args: any[]) { // @ts-ignore
172
+ let ret: NodeJS.Timeout
173
+ if (_.isFunction(cb)) {
174
+ const original = cb
175
+ cb = function(this: NodeJS.Timeout) { // remove fired one-shot timers so plugin unload only tracks pending work
176
+ _.pull(timeouts, ret)
177
+ return original.apply(this, args)
178
+ }
179
+ }
180
+ ret = setTimeout(cb, delay, ...args) as any // 'any' to allow build of frontend and admin
181
timeouts.push(ret)
182
return ret
183
},
@@ -713,4 +721,4 @@ export function getMissingDependencies(plugin: CommonPluginInterface) {
721
: ''
722
return error && { repo: dep.repo, error, id: res?.id }
723
}))
716
-}
\ No newline at end of file
724
+}