From d07ae18a92aae1f92825501f36cd0803b55bb4ed Mon Sep 17 00:00:00 2001
From: Rob Swindell <rob@synchro.net>
Date: Thu, 9 Jun 2022 20:22:40 -0700
Subject: [PATCH] Force a garbage collection in the event "wait forever" loop

This appears to fix the "lots of user.dat files open concurrently" behavior
that remains when a browser/client has the webv4 page open for a long
duration.

Eventually, the User objects created in this loop would be cleaned (and the
user.dat file descriptors closed), but the default garbage collection interval
(configurable) is 1000 calls to the CommonOperationCallback function. This could
be as as long as 1000 times through this loop before GC occurs.

Since this is not a performance sensitive loop (we have a call to sleep for a
full second) just force a garbage collection for each loop iteration.
---
 webv4/root/api/events.ssjs | 1 +
 1 file changed, 1 insertion(+)

diff --git a/webv4/root/api/events.ssjs b/webv4/root/api/events.ssjs
index ac9bfa8588..7aa6e4b447 100644
--- a/webv4/root/api/events.ssjs
+++ b/webv4/root/api/events.ssjs
@@ -53,6 +53,7 @@ while (client.socket.is_connected) {
             delete callbacks[e];
         }
     });
+    js.gc();
     mswait(1000);
     ping();
 }
-- 
GitLab