Mafia freezes and becomes unplayable, don't know if it is with Mafia or my system

deadleeplatapus

New member
I have had no problems with my computer and using KOLMafia for about 3 weeks. Then it started to lag and then freeze up. I hadn't done anything different with any of my programs on my computer and didn't think I did any changes to KOLMafia either.

I looked back through the forums, and someone mentioned that since this might not be a bug, it should be posted in Community support, so I hope this is where it should go.

FYI, I am not well-versed in Computer technology and tech speak (KOLMafia basic info is barely within my grasp of knowledge), but hopefully could help diagnose the problem.

Chrome for the browser
Windows 10



Problem:

In running Mafia, it will run about 15 to 20 adventures before lagging and maybe running another couple and then freezing up.
When trying to log out of Mafia, it hangs on different things and won't log out. I have to shut it down.
When I bring it back up, it freezes on different things (like checking moon signs, or updating storage, or doing breakfast) and won't bring up the relay browser or won't bring it up all the way.
I may have to shut down and restart it a couple of times for it to get to a point that I can it to run another 20 adventures or so.

What previously had taken about 10 to 20 minutes to burn my 200+ turns (just adventuring in one zone with no changes or anything), now takes over a few hours.

What I have done to try and fix the issue:
- I have updated to the most recent build. Did not change the lag
- I have changed the location to another folder on my computer. I started with only the daily build, and then added some scripts - like Ezandora's Guide, CHiT, and other helpful assisting scripts. - still lagged on simple turn burning.
- I installed the Mafia on a thumb drive - still lags and freezes up, no change.
- I made explorer as the browser - no change, still freezes and lags

- Thought that maybe it was my Antivirus. I uninstalled Mcafee. - I tried with just Windows Defender and it still freezes.
- I installed another antivirus - Avast. and still freezes
- I uninstalled Java and then reinstalled the current java. still freezes,


So I may have shot myself in the foot for help by deleting my old builds and copies of mafia that were on my computer. I see that I only have Debug's from Feb 09 and Feb 10th 2018. The other Debug's that I have were from Dec 2017 and before.

I would appreciate any help that can be given to see if I can get back to using mafia daily with the many restarts and freezing. Thank you in advance!

Edit: If you think you may be able to help, please reply here or shoot me a kmail in the game. I have access to the game at work, but not usually the forums. Thanks!
 
Last edited:

WARriorer

Member
I wish to add that OP isn't alone in facing these problems - I too have had the exact same issues with Mafia starting from January 2018 (also running Windows 10).

In a similar fashion, I have
- Reinstalled Java (Java 8, Java 9, JRE1.8.0) and have tested them independently (by uninstalling all but one) with the latest daily builds and KoLMafia 17.12.
- Completely deleted all files and logs related to KoLMafia, re-downloaded and ran it in a new, separate folder (reinstalling all the scripts and rewriting my CCS)
- Tried running KoLMafia on my laptop instead of my desktop
- Turned off my Anti-Virus
- Changed the default browser
- Cleared my Java Cache
- Ran memtest86 overnight to check if there was any memory issues (none found)

Certain things I've noted while trying to fix the issue myself (albeit to no avail):
- Vanilla KoL experiences no lag, but accessing links throughout the kingdom (even the main page itself) using the relay browser on KoLMafia does have a significant lag time
- Closing KoLMafia when it freezes (as described by OP) does not always delete the "active_session.1" file. This occurs when there is still a JRE process running in the Task Manager, which prevents the deletion of the file. (Ending the process in Task Manager allows for the manual deletion of the file). Opening KoLMafia while the "active_session.1" file exists creates an "active_session.2" file, although multiple sessions do not appear to be the cause of the lag/freezing (regardless of whether I actively try to ensure a single session, it doesn't seem to have any effect on the lag/freezes)
- Scripts appear to end prematurely, especially when the script attempts to access the inventory or change equipment (specifically, VeracityMeatFarm.ash crashes on these instances - red links which give access to the individual inventory tabs appear on the Graphical CLI; crashes also occur when changing to the Protonic Accelerator Pack). Scripts also do not appear to be able to run properly (VeracityMeatFarm.ash is unable to acquire items and I have to acquire them manually [even though I constantly check prefref to ensure that the meat amount is set well above the items I need to acquire]). I believe this may be due to the fact that KoLMafia is unable to access the data (potentially due to the lag/freezes), which brings up edge/unique cases such as the time I logged in but KoLMafia did not identify that I had any items whatsoever (e.g. the dropdown box in the Gear Changer did not show any other options other than the items I was currently equipping).

I have also noticed that a few other KoLers are also experiencing the same symptoms:
https://www.reddit.com/r/kol/comments/7pftgo/kolmafia_lag/

Digging up past issues with KoLMafia on various forums and trying their solutions also does not seem to have helped solve this issue.

I would also greatly appreciate if any KoLMafia developers could provide any help in troubleshooting this issue. Many thanks in advance! (I really suspect that the issues are the same and hope I am not unwarrantedly hijacking this thread)
 

fronobulax

Developer
Staff member
I have no specific suggestions or reasons to believe anything I say might apply. I am responding because both reports are well written and you deserve some kind of response/acknowledgement.

The active session files are mafia's way to limit running instances of mafia to two. If mafia does not exit normally then they will be left behind. As noted, if any are present and mafia is not running, the standard procedure is just to delete them.

I have sometimes been informed of mafia detected weirdness if I open the gCLI window before logging in. Some messages have appeared there that are not logged anywhere else and indicate that a communication error occurred. Mafia just sits there when retrying or informing the user or treating the error as fatal and exiting might be expected behavior. Worth a shot.

I personally do not like Chat. Because it is a feature I personally don't use I am willing to blame all sorts of things on it, even when there is no justification for doing so. Nevertheless I have noticed some thread related start up problems when Chat loads at start up. In my case they were intermittent, but seem to go away, after I stopped opening Chat at startup and closed it ASAP after I was done. (Easiest way to see if your fax worked is to open a chat window and then fax, for example). So I would ask whether not opening or using chat changes anything.

I can't recall whether jstack is part of the run environment or the development environment. But if it is on your system it might be worth it to run it next time things slow to a crawl and share the results.

While mafia is running, open a command line and type

jps -1

That should return a number, the processID of currently running Java processes. If there is no number, Java is not running which means mafia is not running. If there is more than one it means there are several Java processes and that might be the key.

If it returns one number (the PID) then type

jstack {PID}

Copying the results and pasting them here might trigger something.

{PID} is short hand for the process ID. Just type the number, not bracket number bracket.

Do any other Java applications run fine on the system?

If you run Task Manager is the Java task using a lot of CPU, Memory or Network. Is the amount used a significant portion of the available resources?

A general slowdown that gets worse over time can be related to memory usage. Does triggering garbage collection (there's a button on the top right if memory serves) effect things?
 

fronobulax

Developer
Staff member
I skimmed the reddit comments and was reminded that I have had lag in the relay browser because of my browser settings. Various ad blockers or cookie managers would introduce a lag that went away when I explicitly disabled them. At least once, but not repeatably, I got a message from the browser that said a script on the page was taking a long time. Did I want to abort? So a plain vanilla instance of the browser or changing which browser mafia is using might shed some light.
 

lostcalpolydude

Developer
Staff member
I wish to add that OP isn't alone in facing these problems - I too have had the exact same issues with Mafia starting from January 2018 (also running Windows 10).

Does that mean you can use versions from before then without having any issues?

A nice starting point would be "this version causes problems, this other version from soon before that does not cause problems".

I don't think a list of anecdotes will help with fixing anything.
 

WARriorer

Member
Thanks for the quick responses!

I personally do not like Chat. Because it is a feature I personally don't use I am willing to blame all sorts of things on it, even when there is no justification for doing so. Nevertheless I have noticed some thread related start up problems when Chat loads at start up. In my case they were intermittent, but seem to go away, after I stopped opening Chat at startup and closed it ASAP after I was done. (Easiest way to see if your fax worked is to open a chat window and then fax, for example). So I would ask whether not opening or using chat changes anything.

I had also thought that chat might have been an issue. Unfortunately, it doesn't seem to be the case (especially not when considering there are issues logging in through KoLMafia before anything is actually being done).

I can't recall whether jstack is part of the run environment or the development environment. But if it is on your system it might be worth it to run it next time things slow to a crawl and share the results.

While mafia is running, open a command line and type

jps -1

I'm probably doing this wrong, but opening Command Prompt on Windows 10 and typing "jps -1" gives "'jps' is not recognized as an internal or external command, operable program or batch file."

If you run Task Manager is the Java task using a lot of CPU, Memory or Network. Is the amount used a significant portion of the available resources?

A general slowdown that gets worse over time can be related to memory usage. Does triggering garbage collection (there's a button on the top right if memory serves) effect things?

I'm afraid garbage collection does not seem to help at all when KoLMafia freezes up. I have repeatedly clicked on it when it hangs (to no avail). While KoLMafia is running, it uses ~250MB (I have an 8GB RAM, which isn't running anywhere near full capacity while I'm running KoLMafia). CPU and Network usage are also generally <10% with the other things I'm doing on the desktop (e.g surfing the net). There are times when the CPU usage spikes up to 50% for a split second (e.g. going from the login window to the logged-in interface), but this is not the case when KoLMafia freezes (currently testing [and freezing on] cc_snapshot.ash).

I skimmed the reddit comments and was reminded that I have had lag in the relay browser because of my browser settings. Various ad blockers or cookie managers would introduce a lag that went away when I explicitly disabled them. At least once, but not repeatably, I got a message from the browser that said a script on the page was taking a long time. Did I want to abort? So a plain vanilla instance of the browser or changing which browser mafia is using might shed some light.

I have changed the browser from Chrome to Firefox to Internet Explorer without much success in resolving this issue.

Does that mean you can use versions from before then without having any issues?

A nice starting point would be "this version causes problems, this other version from soon before that does not cause problems".

I don't think a list of anecdotes will help with fixing anything.

It doesn't appear to be an issue with the version - having done this previously (and just trying out version 18273 from 2 Dec 2017, which freezes while "Looking at item #...").

Apart from the anecdotes, would any other information be helpful in troubleshooting? (and relatedly, how can I go about collecting such information?)
 
Last edited:

WARriorer

Member
I don't think a list of anecdotes will help with fixing anything.

Also, I do apologise if the anecdotes made the whole post convoluted. I didn't want to come across as demanding a solution without putting in the necessary work/research myself, especially so if it turns out that there was a quick and simple fix that I had missed out (and I'm sure OP had the same intentions).
 

lostcalpolydude

Developer
Staff member
The anecdotes are fine. I'm just pessimistic about those anecdotes, or others that people might feel like contributing, leading to any fix.
 

fronobulax

Developer
Staff member
Thanks for the quick responses!

Sounds like jps and jstack are part of the development environment which you don't have installed. Not worth getting you to try that yet.

Since I infer sometimes the symptoms occur at startup.

Consider this:

Launch KoLmafia but do not log in. (Disable auto login and restart if necessary).
Open the gCLI using General->Graphical CLI from the Login Screen
Wait because this step takes more time than most people should but still less than two minutes on my system.
When the gCLI opens, switch to it.
Click the Preferences button.
Navigate to Look & Feel -> Main Interface.
Make sure Relay Server and Loathing Chat are NOT listed under Startup as Window and Startup in Tabs.
(Change things if they are).
Close the Preferences Window.
Optionally separate the Login and gCLI windows so you can watch the latter while interacting with the former.
Select the Login Window and log in.
Observe the gCLI.

My experience has been that if something unexpected happens it appears in the gCLI and with a red font color.
On my system, I open the gCLI in a tab during start up. This it is expected when KoLmafia closes the gCLI window and creates a gCLI tab. Just switch if/when that happens and know if it did that is expected.

I notice I just did that and never saw "Looking at item". It is emitted by the code in APIRequest but I wonder why you see it and I don't? In Ye Olden Days when I got paid to write code we had several problems with JSON. They were all related to our code failing to link at run time to the expected JSON library. Grasping at straws but maybe there is something in APIRequest handling...
 

heeheehee

Developer
Staff member
Frono: the "Looking at item #..." message is passed into KoLmafia.updateDisplay(), which shouldn't show up in the gCLI (I think).

edit: I also believe it only should invoke that if you encounter an item that isn't in Mafia's datafiles.
 
Last edited:

fronobulax

Developer
Staff member
Frono: the "Looking at item #..." message is passed into KoLmafia.updateDisplay(), which shouldn't show up in the gCLI (I think).

edit: I also believe it only should invoke that if you encounter an item that isn't in Mafia's datafiles.

If I followed it right, it ends up in System.out but there is so much opportunity for me to be wrong... That said, I didn't see it displayed anywhere during my quick test so there is something different. If you are correct in that it is an item not found in KoLmafia's database then either the database got corrupted or it is something "their" character has that mine doesn't. Hmmm....
 

theo1001

Member
I think you missed this.

It doesn't appear to be an issue with the version - having done this previously (and just trying out version 18273 from 2 Dec 2017, which freezes while "Looking at item #...").

So a variety of items (crimbo, clan carnival, etc) could have triggered it.

I can also confirm that the "Looking at item #..." appears at the gCLI for items not found in the mafia database. It is where i copied the items i pasted in the Feb 2018 IotM thread.
 

WARriorer

Member
Sorry for the late response. It was already way past midnight at the time of my last post.

Sounds like jps and jstack are part of the development environment which you don't have installed. Not worth getting you to try that yet.

Since I infer sometimes the symptoms occur at startup.

Consider this:

Launch KoLmafia but do not log in. (Disable auto login and restart if necessary).
Open the gCLI using General->Graphical CLI from the Login Screen
Wait because this step takes more time than most people should but still less than two minutes on my system.
When the gCLI opens, switch to it.
Click the Preferences button.
Navigate to Look & Feel -> Main Interface.
Make sure Relay Server and Loathing Chat are NOT listed under Startup as Window and Startup in Tabs.
(Change things if they are).
Close the Preferences Window.
Optionally separate the Login and gCLI windows so you can watch the latter while interacting with the former.
Select the Login Window and log in.
Observe the gCLI.

My experience has been that if something unexpected happens it appears in the gCLI and with a red font color.
On my system, I open the gCLI in a tab during start up. This it is expected when KoLmafia closes the gCLI window and creates a gCLI tab. Just switch if/when that happens and know if it did that is expected.

I notice I just did that and never saw "Looking at item". It is emitted by the code in APIRequest but I wonder why you see it and I don't? In Ye Olden Days when I got paid to write code we had several problems with JSON. They were all related to our code failing to link at run time to the expected JSON library. Grasping at straws but maybe there is something in APIRequest handling...

With the latest build (r18460) it still freezes on logging in (at different stages) with no red text appearing. For the preferences, I have nothing set on "Startup as Window", and only 5 items under "Startup in Tabs":
Adventure
Graphical CLI
Purchases
Gear Changer
Skill Casting

I can also confirm that the "Looking at item #..." appears at the gCLI for items not found in the mafia database. It is where i copied the items i pasted in the Feb 2018 IotM thread.

Yep, with r18460 the "Looking at item #..." no longer appears, although the freezes still occur (and thus doesn't seem to be an isolated issue with the looking up of unknown items).
 

heeheehee

Developer
Staff member
I can also confirm that the "Looking at item #..." appears at the gCLI for items not found in the mafia database. It is where i copied the items i pasted in the Feb 2018 IotM thread.

You sure that it appears in the gCLI? Typically that's caused by invocations to RequestLogger.printLine(), as is the case with "Unknown item found: ..." (which is what you seem to be citing), whereas the "Looking at item #.." message appears in ApiRequest and is passed to KoLmafia.updateDisplay(), which (if my memory serves me correctly) just updates the status text bar on the login screen and the Adventure frame. (Aside, you also shouldn't copy from the gCLI, since it turns tabs into spaces)

With the latest build (r18460) it still freezes on logging in (at different stages) with no red text appearing.

I'm a bit late to the game, but can you upload a debug log (preferably with network requests enabled)? Steps to set up those below:

1. General > Preferences, Extra Debugging > check "Verbosely log communication between KoLmafia and browser"
2. Help > Start Debug Log
3. Try logging in.

If nothing else, this should tell us the last section of code Mafia successfully executes, but if we're lucky, it'll point to further problems.
 

WARriorer

Member
If nothing else, this should tell us the last section of code Mafia successfully executes, but if we're lucky, it'll point to further problems.

I've tried replicating the freeze for the log in but so far it has been smooth (the freezing behaviour does seem quite erratic).

However, I can reliably reproduce the freezes when running scripts. Here is a debug log from the log in up until it freezes while running EatDrink.ash:
https://paste.ee/p/vLzod

It is a 3.1MB file (due to the verbose debug log), and it seems to freeze while awaiting the server reply.

I'll run another debug log when I execute VeracityMeatFarm.ash to see if I'm able to capture the instance of the script crashing.
 
Last edited:

theo1001

Member
You sure that it appears in the gCLI? Typically that's caused by invocations to RequestLogger.printLine(), as is the case with "Unknown item found: ..." (which is what you seem to be citing), whereas the "Looking at item #.." message appears in ApiRequest and is passed to KoLmafia.updateDisplay(), which (if my memory serves me correctly) just updates the status text bar on the login screen and the Adventure frame. (Aside, you also shouldn't copy from the gCLI, since it turns tabs into spaces)

Yeah, i double-checked my last post before posting here.

Looking at item #9731...
Unknown item found: Fabiotion (9731, 566108269)
--------------------
9731 Fabiotion 566108269 wbpotion.gif usable t,d 5
Item Fabiotion Effect: "Faboooo", Effect Duration: 20
--------------------

I am assuming that "Looking at item #9731..." was the same line and everyone was just omitting the item id but i guess that technically it could be different lines.

(Aside, you also shouldn't copy from the gCLI, since it turns tabs into spaces)

I wasn't aware that it did that or that it was a problem.

I'll copy them from the session log in the future.
 

heeheehee

Developer
Staff member
It is a 3.1MB file (due to the verbose debug log), and it seems to freeze while awaiting the server reply.

I'll run another debug log when I execute VeracityMeatFarm.ash to see if I'm able to capture the instance of the script crashing.
Thanks for the debug log.

Looks like the hang isn't tied to a mall search per se, since there are multiple successful mall searches before that. Now that I've taken a closer look at the OP: I'm somewhat more inclined to think it's your system somehow (especially since it's not happening in a consistent place).

- If you bring up task manager (ctrl-alt-del) during one of these hangs and look for the task (probably KoLmafia, but possibly Java / JRE), does it look like anything's saturated (CPU, Memory, Disk, etc)? My first guess is that somehow Java is running out of memory (and trying to do a stop-the-world GC while swapping, e.g.).

- Has Mafia ever recovered from one of these hangs (if you just leave it open for a few hours)? (would lend more credence to Mafia swapping while performing very slow operations)

- Is the UI still responsive (i.e. can you still interact with Mafia), or is that frozen too (probably would see Windows's "(Not Responding)" indicator)? (i.e.is the entire JVM having issues, or is it just a processing thread that's getting deadlocked somewhere?)


I wasn't aware that it did that or that it was a problem.

I'll copy them from the session log in the future.

Yeah. The gCLI is actually a HTML renderer, so it renders tabs as spaces. The value of copy-pasting those overrides is that it makes it easy for developers to add them directly to mafia datafiles.
 

WARriorer

Member
- If you bring up task manager (ctrl-alt-del) during one of these hangs and look for the task (probably KoLmafia, but possibly Java / JRE), does it look like anything's saturated (CPU, Memory, Disk, etc)? My first guess is that somehow Java is running out of memory (and trying to do a stop-the-world GC while swapping, e.g.).

Nothing appears to be saturated in the task manager (CPU <10%, Memory < 50%, Disk ~0%, Network ~0%, GPU ~0%). I too initially wondered if it was an issue with my system (desktop), hence I tried running Mafia on my laptop (which worked fine before I encountered this issue), but the same lag/freezing also surfaced there.

- Has Mafia ever recovered from one of these hangs (if you just leave it open for a few hours)? (would lend more credence to Mafia swapping while performing very slow operations)

Some of the freezes appear to be temporary, lasting anywhere between 5-30mins. Other freezes on log in appear to last well over a few hours with no signs of recovery.

- Is the UI still responsive (i.e. can you still interact with Mafia), or is that frozen too (probably would see Windows's "(Not Responding)" indicator)? (i.e.is the entire JVM having issues, or is it just a processing thread that's getting deadlocked somewhere?)

The UI is responsive. While logged in, it is possible to type in the gCLI, which allows for the queuing of additional scripts (although none of the scripts actually run). It is also possible to open the relay browser to carry out actions (which are reflected and recorded on the gCLI) while the scripts freeze.
(I would note that the relay browser is significantly laggier than Vanilla KOL, which may hint at a possible reason why Mafia appears to freeze while awaiting for the server reply)

I do have another debug log which captured the freezing during logging in, although I don't think it would shed any further light on this issue (similar to the previous debug log, it appears to hang while awaiting the server reply): https://paste.ee/p/okRy2
 

deadleeplatapus

New member
First off - Thank you for responding and assisting with this.

I had my KOLMafia freeze and I closed it. I went into the task manager and it still showed that it was open, so it might have had the problem where I had more than one (or two) instance(s) of mafia going at the same time which isn't good per a previous post.
I killed the java, and restarted my computer.

At this point, my mafia is running better than it had when I posted this. I can run scripts and actually just burn turns now in any given location.

Thank you for your help and if it starts happening again, I will come back to get assistance.

( I am glad that worked for me, as reading the other posts totally threw me for a loop. I tried to put the --> jps -1 <-- in the CLI and it gave me an error, so you were probably talking about a different place to put it. I tried to drag and drop my logs into a reply here, but I found that didn't work. If I have more problems, I will come back and hopefully everyone would be as helpful and patient with me as you have been with WARriorer. I really enjoy the KOL community and appreciate the helpfulness there and also here on this forum. Kudos!!)

Edit: also, I was not able to reply earlier as RL came up and bit me in the buttocks.
 
Last edited:

fronobulax

Developer
Staff member
Whoops. When I said 'command line' above in connection with jps and jstack I meant the operating system command line ("Command Prompt") and not the KoLmafia gCLI.

This is sounding like a threading issue but I'm not sure what I can bring to bear on the problem yet.
 
Top