Bug - Cannot Reproduce Kolmafia keeps crashing due to out of memory error

neomaster

New member
This started for me a couple of days ago. I've tried updating Kolmafia, rebuilding preferences and tried 2 new clean installs of mafia and all fail to run a farming script which I've been running successfully for months.

The script runs fine for the setup and first few combats, but after a short while it just stops at a random point with this message:

Request 7 of 100 (Dinseylandfill: Barf Mountain) in progress...

[111867] Barf Mountain
Preference lastEncounter changed from angry tourist to horrible tourist family
Encounter: horrible tourist family
Preference _lastCombatStarted changed from 20210818044947 to 20210818044950
(Barf Farming.ash, line 652)
Script execution aborted (java.lang.OutOfMemoryError: Java heap space): (Barf Farming.ash, line 652)

After that, basically nothing works without restarting mafia entirely. I've also noticed that I've had a -lot- of broken images lately, and not sure if that's something to do with it. Figured a clean install might also resolve that, but the same few images are consistently broken with each clean install, despite also doing a cache clear.

I've had a quick look around to see if there's anything else I could try, but haven't had much luck. Let me know if there's any extra information I can give :)
 
Last edited:

heeheehee

Developer
Staff member
Hm. My initial reaction was that this could be related to r20835, which we expected to noticeably increase the memory footprint of scripts, but if this has been happening for a few days, that is probably not the immediate cause (although it likely doesn't help).

Do you have any debug logs? How big is the script? What revision(s) were you using? Do you know how much RAM Mafia was actually using? (A workaround might be to run Mafia with some special flags ("java -Xmx 1G -jar KoLmafia.jar" to set Java's max heap size to 1 GB, for instance, which is larger than Oracle Java's default of 256MB; you can also do some fiddling with your environment. But this is merely a workaround, and the long-term solution would be for us to work on reducing our current RAM usage.)

Regarding broken images: there was a thread a little while back but no resolution that I'm aware of.
 

heeheehee

Developer
Staff member
(OpenJDK by default will use up to a quarter of your available RAM, while Oracle Java defaults to 256MB.)
 

neomaster

New member
Ahhh, yeah that's probably fair. I've definitely had this issue persist through a few different daily builds.

I don't think there are any debug logs that were generated when the errors have happened, but if there's a way of getting that information I'm happy to reproduce the error. The script is 103kb, I'd been using a couple of revisions but the most up to date one I had was r20831. Not sure how much RAM mafia was using at the time but can keep an eye on that next time I attempt to run the script. How would I go about setting those flags?

Yeah, I saw that! Wasn't sure if it was related to my memory issues or not, but they more or less broke at the same time my scripts stopped working so I figured I'd mention it. My mafia definitely seems to be having trouble creating/updating files, it doesn't seem to want to create session logs, update preferences or cache images.

I'm running oracle but could definitely try openJDK, thanks for the ideas so far! Appreciate you both replying :)
 
Last edited:

fronobulax

Developer
Staff member
There is pretty much nothing safe to do after "java.lang.OutOfMemoryError: Java heap space" except shut down mafia and restart. Indeed anything you do may also fail because there is not enough memory.

There is a memory monitor in mafia. Log in and the top row of icons should have a bar with numbers ("145 MB / 1990 MB") and a clock face button. Pressing the button will force a garbage collection. If your problem is related to creating a lot of objects that are only needed once, that might be a work around. You could report the numbers you see there although that may not lead to a diagnosis.

It is tedious but given some recent changes to parsing and your belief that the script had not changed, perhaps trying mafia versions so that we know revision X does not have the problem but X+1 does, If it is a side effect of recent changes that will tell us which change to focus on.

If you have a JDK and not just a JRE installed there are ways to get a memory dump after a heap overflow that we could rediscover and tell you. If that doesn't make sense then you probably only have a JRE and never mind ;-)
 

neomaster

New member
I've tried a few of the things listed in this thread, sadly without much success. Most notably I added a flag to increase the memory my JRE could use, but it appears to have had no effect? It still reads x/247mb within the mafia client regardless of what I specify. A notable issue is definitely that mafia appears to be unable to create/edit any new files, and I think that may be the source of/connected to the problem somehow. I've not had a single session log be produced since the issue began, I've just noticed now that instead of that I only have several "active_session.1" files (with increasing numbers at the end for each file). I'm wondering if this is also what's meaning I have a lot of broken image files, I also can't update preferences without them reverting the moment I close mafia.
 
Last edited:

fewyn

Administrator
Staff member
Where are you storing your Kolmafia installation? Some places in Windows have permission issues afaik. Maybe try creating a new folder elsewhere with a fresh mafia install and see if the issue occurs?
 

fronobulax

Developer
Staff member
I would manually delete the active_session files when mafia is not running. That won't solve this problem but may prevent others.

In addition to checking that the user running mafia has permissions to write files in the mafia directory tree, make sure there is actually space on the device. mafia's file handling is what it is and failures (deliberately) do not always cause aborts and the reasons for failure are not always reported to the user.

In that spirit, I typically run mafia by double clicking on the jar file. But that sometimes swallows messages of interest so running it from a command line may get the messages displayed and those, in turn, may bear on this issue. (Instructions available on request, if needed).
 

lazy_fire

New member
I've tried a few of the things listed in this thread, sadly without much success. Most notably I added a flag to increase the memory my JRE could use, but it appears to have had no effect? It still reads x/247mb within the mafia client regardless of what I specify. .
If you're using the flag posted above, I found it should be "-Xmx1G" instead of "-Xmx 1G". Try removing the space if you have it.
 

neomaster

New member
Sorry it's taken me a while to reply, I've been running test runs of scripts over a couple of days and it's taken a while to have anything of note to report!

I tried a few more clean installs to no avail, and double checked that I'd used the right flag to increase java memory. After that I booted up an older computer and rebuilt a truly clean install of mafia, before attempting to run the script I'd been failing to run. It's been running fine for 2 days worth of run throughs now, which leads me to conclude that the script and mafia are probably not the issues here.

I'm going to try a few bits to get my newer computer (the one which can't run the script) to work again. I imagine it may be a java issue, or something wrong with the computer itself. Really appreciate all the help!
 
Top