Future fix Game is leaking handles

Posts
78
Reaction score
106
My os is windows 10 and I noticed that MB II allocates huge amount of windows handles, but does not release them. This does have impact on the actual game, because a very high number of assigned handles causes the WMI provider service to go into overdrive and use a lot of CPU.
In my case, I noticed this issue a few days ago, because the game became very unresponsive (even though the game showed I have 90 FPS - my set max, it was laggy as if I had about 15 fps). Checking the task manager showed that the WMI provider was taking about 40% of my CPU. After some googling I came upon the idea of checking how many handles are currently in use by various processes.

I did not make screenshot at that time, but these were the top three processes when ordered by handle count:
Third place was taken by dropbox with ~5800 handles
Second was System process with ~6100 handles
First was mbii.x86 with ~360.000 handles


I am not sure what the cause is, so here's some info from my system and some tests that I did.

System info
  • OS: Windows 10 x64
  • CPU: Processor Intel Core i5-6660K, 3.50GHz
  • RAM: 16 GB (do note that at the time I was doing tests, I still had about 50% RAM free)
  • I do not use any replacements/addons in MBII, only binds

Tests
Opening the game to main menu had the game allocate ~1800 handles.
Next, I joined an empty server (tried open mode server with mb2_deathstar, later tried empty duel mode server with mb2_duel_dotf).
Even later, I joined populated server.

These are the test cases that I tried:
  1. In empty server - stay in spectate, not moving/doing anything, with minimized game
    • Leaked ~53 handles per second
  2. In empty server - joining the game as only player, not doing anything
    • Leaked ~72 handles per second
  3. In empty server - joining the game as imp on deathstar, running circles around Falcon
    • Leaked ~89 handles per second
  4. In empty server - joining the game as imp on deathstar, throwing fire nades around me
    • Leaked ~63 handles per second
  5. In empty server - joining the game as imp on deathstar, throwing and dying to fire nades
    • Leaked ~80 handles per second
  6. Swapping back to main menu
    • No leaks, actually total handle count went down by 8 handles
  7. Joining populated server
    • Leaked ~75 handles per second
  8. Joining populated server, turning auto-recording off
    • Leaked ~90 handles per second

So from what I gather, most leaks happened when I was running (and only running) around the map, then when visual/sound effects (from fire nade) and special effects ( UI flame effect) were active.
Switching auto-recording off does not seem to have impact - if anything, I would have expected slower handle leak with auto-recording off. My guess for the 90 handle leak is due to what I (and other players) were doing during the round.

I used the following powershell function to count the handles and just called it manually:
Code:
function Foo
{
    param(
        $delay = 60,
        $process = 'mbii.x86'
    )

    Write-Host "Starting handle count test for process `'$process`' ($(Get-Date))..."
    $handleBefore = (get-process $process).Handles

    Write-Host "Waiting for $delay seconds..."
    Start-Sleep $delay

    $handleAfter = (get-process $process).Handles
    $diff = $handleAfter - $handleBefore;
    $leak = $diff / $delay;

    Write-Host "Finished. Test results:"
    Write-Host "   Handles at start: $handleBefore"
    Write-Host "   Handles at end:   $handleAfter"
    Write-Host "   Difference:       $diff"
    Write-Host "   Leaks per second: $leak"
}
Gathering data for test cases 1.-6. above took me about 52 minutes. During that time, the game allocated 161.904 handles total.
Also for comparison, I played other games - WoW, The Outer Worlds and Factorio:
  • WoW had allocated 820 handles after playing for 1 hour and 15 minutes
  • The Outer Worlds had allocated 8600 handles after 2 hours
  • Factorio had allocated 720 handles after 1 hour
so this seems to be problem in MBII, rather than some configuration in my PC, but I may be wrong here.
 

Defiant

Project Leader
Movie Battles II Team
Code Leader
Posts
790
Reaction score
1,065
We have been unable to duplicate this at all. You have three times as many handles on the Main Menu as you should have when in game.

Please can you ensure you are not running a custom OpenJK build, nothing is hooking into the MBII process for any reason (Other than the required launcher) - this may require you to temporarily disable any anti-virus product you are using and attempt to reproduce the problem you are seeing using JAMP.

If none of these help you could provide more information by interrogating the process with this tool:

.
 
Posts
78
Reaction score
106
@Defiant I am not running any custom build AFAIK. Had the base game (cd version), downloaded launcher and installed MBII through it. Also, the launcher is set to MB II Client engine (if that helps anything).
I ran the handle.exe you linked, wrote the output to file before joining server and after playing for a while, then compared the two files. Saw that there is a lot of mutant handles like this one:
3CC0: Mutant \Sessions\18\BaseNamedObjects\{BF48B3D4-720D-487F-9BED-F70CF20934BF}
Only the hexa number at start was changing, but the base named object id is same for all entries.
Do you know of a way to identify what this ID points to?
 
Posts
78
Reaction score
106
I was not sure how to check if launcher is up to date, so I downloaded the launcher again.
I noticed that the launcher I was starting from my desktop shortcut pointed to launcher, which was misplaced in a parent folder few levels above GameData folder, so I changed that. Now when I start the game, it allocates ~700 handles. However once I join the game, it starts leaking at ~90 handles per second again.
Running the handle.exe utility this time returns only ever increasing list of Mutant handles, but it no longer shows the path "\Sessions\18\BaseNamedObjects\{BF48B3D4-720D-487F-9BED-F70CF20934BF}"
 

Defiant

Project Leader
Movie Battles II Team
Code Leader
Posts
790
Reaction score
1,065
What happens when you play on an anti-cheat enabled server?
 
Posts
78
Reaction score
106
I tried BG server and Tin open server - both with anti-cheat on. Nothing happens there - I can play normally. However the handle count was still increasing.
I noticed - that in both cases where one server is populated and the other is not, if I do not move (even in spectate), then I leak about 50 handles, however if I move a lot, I leak up to 90 handles. Having players around me seemed to have no real impact on the handle leak.
 

Defiant

Project Leader
Movie Battles II Team
Code Leader
Posts
790
Reaction score
1,065
Not sure why we cant reproduce this - but it should be fixed in the next update.
 
Posts
78
Reaction score
106
Is there perhaps some command that would dump some useful info for you?
Also, since it leaks more when I move around, perhaps its related to drawing the map? Perhaps a buggy graphics driver? I have GeForce GTX 1060 and drivers are up to date, tho
 

Defiant

Project Leader
Movie Battles II Team
Code Leader
Posts
790
Reaction score
1,065
Nah- it's ok. I can see the bug in code, not sure why it doesnt seem to be affecting anyone else at the moment, it should be fixed in the next release.
 
Top