New client appears to have a Handle Leak

Case number:671071-2004487
Topic:Game: Other
Opened by:Susume
Opened on:Wednesday, November 22, 2017 - 01:02
Last modified:Monday, August 26, 2019 - 20:47

Since taking the new devprev a few days ago, I have noticed game clients growing very sluggish after they have been running for 12 or more hours. I also notice an increasing number of open handles associated with each client as time goes by. Every time a script calls a foldit tool (wiggle, shake, rebuild) it appears the handle count goes up by one. These handles are not given back after the script is terminated. A new client has about 470 handles; the one I am looking at now that has been running for six hours has 22,000 handles.

There was an apparent handle leak a year or so ago, no idea if it is related:

(Wed, 11/22/2017 - 01:02  |  6 comments)

Susume's picture
User offline. Last seen 8 hours 1 min ago. Offline
Joined: 10/02/2011
Topic: General » Game: Other
Type: Suggestion » Bug

Bleh, can't remember to set the category/type.

jeff101's picture
User offline. Last seen 3 hours 57 min ago. Offline
Joined: 04/20/2012
Groups: Go Science
I still experience Handle Leaks on Foldit clients in Windows.
Using Task Manager, I list the number of Handles for each 
Foldit client and usually see this number rising vs time.
It seems that having a high number of Handles slows down 
a client.

I suspect that some Recipes make the # of Handles rise
faster than others, but I don't have good stats on this.
Does anyone have a sense which Recipes/tools/commands 
cause the # of Handles to rise fastest? Do you have any
tips for writing Recipes that make the # of Handles
rise more slowly?

In my C-programming days, I often had to worry about memory
use increasing vs time. If the memory use increased too much,
it would slow down my programs. See below for some details:  
Anyway, in LUA, do we have to worry about memory use increasing 
vs time? I was reading the other day about LUA memory leaks. 
It seemed that if you did something like below:

for k1=1,100 do
   for k2=1,100 do

you should later do like below:


to free the memory used by grid.

I also saw use of commands like below:

-- measure the memory in use:
-- clear the unused memory:
-- measure the memory in use:
-- report the results:
print(string.format('Memory/kB=%f=%f -> %f=%f while Threshold/kB=%f -> %f.',

but when I tried them in a Foldit LUA recipe,
gave the message "attempt to call global 'collectgarbage' (a nil value)", and
gave the message "attempt to call global 'gcinfo' (a nil value)".

Does anyone know how to make gcinfo and collectgarbage work 
in a LUA recipe? Are there other LUA commands we can use instead
to monitor memory or Handles in use? Is there a command that will 
decrease the # of Handles a client is using?

brow42's picture
User offline. Last seen 1 year 37 weeks ago. Offline
Joined: 09/19/2011
Groups: None

After some security consideration, Tlaloc decided to only include a subset of the standard LUA library. Also, there is no pointer to the global table, so you can't look to see what is defined.

The almost complete list of top level functions is here:

LociOiling's picture
User offline. Last seen 6 hours 20 min ago. Offline
Joined: 12/27/2012
Groups: Beta Folders

Old feedback, nothing seems to have changed.

I don't think the previous handle leak feedback was ever resolved, either:

The Foldit implementation of Lua doesn't include "system" functions like gcinfo, and there's no workaround, as far as I know. Likewise, you can't directly read and write files in a Foldit recipe, those functions just aren't on the list.

From what I remember previously, the leak may have something do with starting new threads. Apparently, in Windows, if you start a new thread in the wrong spot, the thread handle never gets cleaned up. So, most likely the leak occurs at the level of Windows calls, and doesn't involve Lua. Without source code, it seems difficult to take it further than that.

rmoretti's picture
User offline. Last seen 8 hours 1 min ago. Offline
Joined: 01/15/2010
Groups: Foldit Staff

Thanks for the bug report. I think I've tracked this down, and the next devprev releases should have a fix which hopefully addresses the bulk of the handle leaks.

LociOiling's picture
User offline. Last seen 6 hours 20 min ago. Offline
Joined: 12/27/2012
Groups: Beta Folders
Status: Open » Closed

Slow reaction here, but the latest version (20190620-2e2a2f9739-win_x86-devprev) seems to have fixed the issue with the handle leak. My game clients are now stable at just over 2,000 handles each. My chat client has been running for over a week, and has accumulated 2,375 handles. Closing this feedback.


Developed by: UW Center for Game Science, UW Institute for Protein Design, Northeastern University, Vanderbilt University Meiler Lab, UC Davis
Supported by: DARPA, NSF, NIH, HHMI, Amazon, Microsoft, Adobe, Boehringer Ingelheim, RosettaCommons