trying to make a mod, accidentally crashed my whole computer

Place to get help with not working mods / modding interface.
Divran
Inserter
Inserter
Posts: 47
Joined: Wed Jan 14, 2015 9:13 pm
Contact:

trying to make a mod, accidentally crashed my whole computer

Post by Divran »

EDIT: Okay I wrote this post so badly that I came across as a massive idiot. If you are confused by the first few responses below, it's my fault. I apologize. New rule: don't write forum posts at 1am.
This post talks about something that I, last night, must have assumed was so simple that everyone would understand it, but apparently not. So I'm editing it so that I don't look like as much of a retard.

What I actually wanted to say here is this:
I was developing a mod and I made an infinite loop by accident. It was 1 am and I simply missed that I was iterating a table while adding values to the same table. It shouldn't have happened. Honest mistake, my fault. Let's move on.

However, it was the result of this mistake that made me post this thread. Nothing I could ever do should ever crash my whole computer. Worst case, running out of memory due to an infinite loop should crash the factorio process, nothing more.
It's never okay for a process to be able to crash your whole computer, regardless of what caused it. The fact that you can do so from inside a mod makes it even worse.

For those of you who don't understand the significance of this, take this example: Currently, the factorio api is pretty limited. We haven't seen mods that add new features that are much bigger than the blueprint string mod or a few train managers. These mods are pretty small compared to behemoths like minecraft's mods. Small mods are easier to test (or - hint to myself! - read through) and find problems before you post them on the internet. If this problem of memory usage is not fixed, then eventually, someone will make a mod that (entirely by accident!) forgets to clear some table or string that builds up slowly over time, due to some convoluted process that spans many files and functions. Anyone who uses this mod will then have their whole freaking computer die on them, seemingly randomly, after a few hours. The mod author will inevitably fix the issue, but not before lots of people has had their computers crash.
I feel it's only a matter of time before this happens, which is why it's good to fix this issue before it does. I've seen it happen before in many different games (minecraft mostly).
Fixing it should be as simple as checking the ram usage at the appropriate time.

Now hopefully this post is a bit better.
Last edited by Divran on Sun May 22, 2016 12:15 pm, edited 4 times in total.

Rseding91
Factorio Staff
Factorio Staff
Posts: 10121
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: trying to make a mod, accidentally crashed my whole computer

Post by Rseding91 »

You've made a mod that exponentially creates entities.

On tick 0 you find all entities and then for each transport belt you find you search for even more entities. Then for each "start" transport belt you find you spawn another entity. On tick 1 you repeat and for each tick you repeat. The number of entities goes up and up and up each game tick as you keep spawning more.

Meanwhile you've made tons of garbage for the Lua garbage collector to clean up from all the entity searching and it can't keep up resulting in all of your memory being used up.

You've simply written a *very* inefficient mod that makes far too much garbage for the Lua garbage collector to take care of - there's no bug happening here. You'll be able to get help in the mod help section.
If you want to get ahold of me I'm almost always on Discord.

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3045
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: trying to make a mod, accidentally crashed my whole computer

Post by DaveMcW »

It doesn't even get to the transport belts. Lines 19-27 create an infinite table during load.

Code: Select all

require "defines"
local directions_to_offset = {
	[defines.direction.north] = {x=0,y=-1},
	[defines.direction.south] = {x=0,y=1},
	[defines.direction.west] = {x=-1,y=0},
	[defines.direction.east] = {x=1,y=0}
}
for k,v in pairs( directions_to_offset ) do
	directions_to_offset[k .. "behind"] = {x=-v.x,y=-v.y}
end
0 = {x=0,y=-1}
0behind = {x=0,y=1}
0behindbehind = {x=0,y=-1}
0behindbehindbehind = {x=0,y=1}
0behindbehindbehindbehind = {x=0,y=-1}
0behindbehindbehindbehindbehind = {x=0,y=1}
...

Divran
Inserter
Inserter
Posts: 47
Joined: Wed Jan 14, 2015 9:13 pm
Contact:

Re: trying to make a mod, accidentally crashed my whole computer

Post by Divran »

Yep I knew it had to do with infinite loops somehow. I just ran out of patience and didn't bother to check the code at all. Point is, nothing I do in a mod should cause my entire computer to crash, so this needs to be fixed regardless. At most, it should close the game once it uses too much ram. How this bug appears is irrelevant. This time it happened by accident. If I'd actually taken the time to look at the code I would've found that problem in a few seconds, but this bug could appear in a much, much larger mod where finding it would be a huge pain, and you wouldn't want to risk crashing your whole computer every time you needed to see if the issue was gone.

@Rseding91
Yep I am aware that the code is bad currently, since it seems I forgot to add the check where it was only meant to do the scan when someone creates a transport belt, not any entity. If that check is added, the code becomes significantly less bad. However the efficiency of this code is irrelevant to this bug, since nothing I do should crash my whole computer. Anyway, seems I've worked up a little more patience. Let's see how far I can get this time. Don't worry, I never had any intention of making this mod innefficient, although I will definitely not make it PERFECT in terms of efficiency. That'd be too much work.

Rseding91
Factorio Staff
Factorio Staff
Posts: 10121
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: trying to make a mod, accidentally crashed my whole computer

Post by Rseding91 »

Divran wrote:Yep I knew it had to do with infinite loops somehow. I just ran out of patience and didn't bother to check the code at all. Point is, nothing I do in a mod should cause my entire computer to crash, so this needs to be fixed regardless.
That's just not how programming and computers work at all.

*Any* and I mean *ANY* program you run has the capability to crash your entire computer. There's nothing that can be done about that short of not running any program. 1 wrong flipped bit in RAM from random errors inherit to computers and the entire thing can crash.
If you want to get ahold of me I'm almost always on Discord.

Divran
Inserter
Inserter
Posts: 47
Joined: Wed Jan 14, 2015 9:13 pm
Contact:

Re: trying to make a mod, accidentally crashed my whole computer

Post by Divran »

I'm aware of this. Mods, though, should be sandboxed, and I'm positive mods in factorio already are (for example you shouldn't be able to use lua to delete important operating system files - if you can, then it's not sandboxed properly). When a mod simply uses too much ram (such as in this case), it should crash the factorio process long before it uses enough ram to crash your computer. Every other game that supports mods already does this.

silverkitty23
Fast Inserter
Fast Inserter
Posts: 117
Joined: Wed May 11, 2016 6:52 am
Contact:

Re: trying to make a mod, accidentally crashed my whole computer

Post by silverkitty23 »

Any such sandbox is going to mean extra processing time to watch what the mod is doing. I could see a case for an opt-in extra-protection mode you use while developing a mod, but why punish *all* mods by making them slower just because very occasionally someone *might* write an infinite loop?

"Every other game..." [citation needed] - especially for use of a all-encompassing word like 'every'. I'm willing to bet a dollar I can find "I crashed my computer..." messages in the "modding help" forums of other games. Gödel always haunts us.

Divran
Inserter
Inserter
Posts: 47
Joined: Wed Jan 14, 2015 9:13 pm
Contact:

Re: trying to make a mod, accidentally crashed my whole computer

Post by Divran »

Checking how much ram the process is using shouldn't slow it down at all, but fine whatever don't fix this then.

Just to show you what I was trying to do
Image

silverkitty23
Fast Inserter
Fast Inserter
Posts: 117
Joined: Wed May 11, 2016 6:52 am
Contact:

Re: trying to make a mod, accidentally crashed my whole computer

Post by silverkitty23 »

I'm not on the development team. Just another programmer with some thoughts. Which is why I emphasized the part where I agreed with you about having an extra-protection mode for developing mods.

When you say: "checking how much RAM it's using shouldn't slow it down at all"... you should say "much" instead of "at all". Of course there will be *some* amount of slowdown. Every single statement executed costs SOME time. Maybe it would be a tiny amount of time, but malloc() might be executed hundreds of thousands of time per second already, so maybe a tiny amount would add up. I dunno without seeing the source of Lua and their integration of Lua.

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: trying to make a mod, accidentally crashed my whole computer

Post by prg »

Rseding91 wrote:*Any* and I mean *ANY* program you run has the capability to crash your entire computer. There's nothing that can be done about that short of not running any program.
Uhm what? A userspace process should certainly not be able to take down the entire system. We're not using DOS anymore. If the system runs low on memory and a process requests more than is reasonably available, the request should simply be denied. The process can then chose to handle this properly or segfault because of it. If the system overcommits memory (grants allocations even if not enough memory is available, hoping it won't actually be used), the process trying to use that memory should just be killed without affecting the rest of the system.

If a process allocating lots of memory takes down the whole system, something is wrong with the system.
Rseding91 wrote:1 wrong flipped bit in RAM from random errors inherit to computers and the entire thing can crash.
Whatever happens in a process's memory should only affect that process. If a random bit flip in kernel memory due to faulty hardware causes system instability, that's entirely unrelated.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

User avatar
ArderBlackard
Long Handed Inserter
Long Handed Inserter
Posts: 74
Joined: Thu May 05, 2016 12:41 pm
Contact:

Re: trying to make a mod, accidentally crashed my whole computer

Post by ArderBlackard »

prg wrote:
Rseding91 wrote:*Any* and I mean *ANY* program you run has the capability to crash your entire computer. There's nothing that can be done about that short of not running any program.
Uhm what? A userspace process should certainly not be able to take down the entire system.
In a perfect world - yes :D But nothing is perfect. There are bugs in OSes, drivers, services which can be triggered by any program either intentionally or not. One cannot just blindly hope that everything will be OK everywhere right after writing the code without some testing. And during testing all kind of magic can happen :)
Gib dich hin bis du Glück bist

silverkitty23
Fast Inserter
Fast Inserter
Posts: 117
Joined: Wed May 11, 2016 6:52 am
Contact:

Re: trying to make a mod, accidentally crashed my whole computer

Post by silverkitty23 »

Some Operating Systems handle this better than others, as well. It's hard to get Linux to crash with a bad process (though quite possible - if you fill the partition /tmp is on, or slow it down so hard that you can't get at the console to issue the kill command), but somewhat easier to get Windows to blue screen.

Divran
Inserter
Inserter
Posts: 47
Joined: Wed Jan 14, 2015 9:13 pm
Contact:

Re: trying to make a mod, accidentally crashed my whole computer

Post by Divran »

I updated my first post because it was terrible.

bNarFProfCrazy
Fast Inserter
Fast Inserter
Posts: 182
Joined: Sat Apr 23, 2016 7:11 am
Contact:

Re: trying to make a mod, accidentally crashed my whole computer

Post by bNarFProfCrazy »

Lets work through the checklist.
Is the bug reproducible on other (people's) systems?
If No, then your system is just somehow broken. Not factorio's fault.
If Yes, then collect the OS and get to the next step.

Which kind of crash is it?
Does the computer stop responding? (Allocating memory takes infinitely long).
Does the computer suddenly reboot/bluescreen? (Please make a screenshot :lol: , photo or write down the error message)

If 1) Then well a memory warning would be cool, but since its a very rare case it should simply be ignored, because the other alternative would be crashing Factorio.
If 2) then Factorio is allocating/writing to anothers processes memory, which should not be possible (TM). Unfortunately I don't know how this can be prevented except the default OS protection. Factorio staff should check their code whether they can do anything about it, but otherwise have to ignore it.

Divran
Inserter
Inserter
Posts: 47
Joined: Wed Jan 14, 2015 9:13 pm
Contact:

Re: trying to make a mod, accidentally crashed my whole computer

Post by Divran »

I didn't see that this thread was moved to modding help. Please move it back to the bug reports subforum. It belongs there. If you are a moderator, please re-read the first post, because I've rewritten it.

Rseding91
Factorio Staff
Factorio Staff
Posts: 10121
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: trying to make a mod, accidentally crashed my whole computer

Post by Rseding91 »

Divran wrote:I didn't see that this thread was moved to modding help. Please move it back to the bug reports subforum. It belongs there. If you are a moderator, please re-read the first post, because I've rewritten it.
No. We're not going to spend time working on trying to prevent mods from making infinite loops.
If you want to get ahold of me I'm almost always on Discord.

Divran
Inserter
Inserter
Posts: 47
Joined: Wed Jan 14, 2015 9:13 pm
Contact:

Re: trying to make a mod, accidentally crashed my whole computer

Post by Divran »

Rseding91 wrote:
Divran wrote:I didn't see that this thread was moved to modding help. Please move it back to the bug reports subforum. It belongs there. If you are a moderator, please re-read the first post, because I've rewritten it.
No. We're not going to spend time working on trying to prevent mods from making infinite loops.
This isn't about infinite loops. Infinite loops are only one way that this can happen. This issue will show up again in the future (mark my words) but in a much less obvious form. Minecraft mods have had this issue for as long as there have been mods. The minecraft server will run more slowly over time until it simply dies. It's true that this is the mod author's fault, and all of the mods in minecraft that have this problem have been fixed at one time or another. The point being that minecraft mods can't crash your entire computer, only its own process. Later, when mods in factorio start becoming more complex, it's not impossible that someone will make a similar mistake. Only this time, your whole computer will crash, and not only the process, unlike minecraft.

My opinion is that a process being able to bring down an entire computer is never okay, no matter what caused it (honest mistake or intentional abuse, doesn't matter). The cause is irrelevant. I already mentioned this in the new OP.
Writing efficient code is my responsibility as a modder. Preventing the game from crashing the entire computer is your responsibility as a developer.

My mistake was creating this thread and not putting any effort into the opening post, and if you had read my new OP you would have seen that I have apologized for that.

(By the way, when the mod portal is added, someone could probably make a mod that instantly crashes the computer of anyone who joins, just to be annoying. If the crashed person was, let's say, writing an important essay at the same time, they might be a little upset.)

EDIT: Also, checking the ram usage of the process (at the correct time) won't slow it down at all, and is easy to do.

FPtje
Manual Inserter
Manual Inserter
Posts: 1
Joined: Mon May 23, 2016 11:47 am
Contact:

Re: trying to make a mod, accidentally crashed my whole computer

Post by FPtje »

Rseding91 wrote: No. We're not going to spend time working on trying to prevent mods from making infinite loops.
Your incompetence is preventing you from seeing the underlying issue here, more importantly, you don't seem to understand who's responsible for what. The underlying issue is not Lua developers creating inefficient mods. The underlying issue is the game being so shit at dealing with this that it crashes not only the game, but the entire device.

This is an exploit in the sense that you can use it to crash servers. Servers might not only be running this game, so the incompetence of the developers refusing to fix this will affect other games running on the system. You may try every responsibility absolving argument in your book, but none of them will justify that both ignorant and malicious Lua scripters have such power over the devices that run their scripts.

And to get back to your earlier argument,
Rseding91 wrote:There's nothing that can be done about that short of not running any program.
Nothing? Absolutely nothing to solve this issue? Surely if this issue is unsolvable, other games with Lua interpreters would have the exact same issue, which is that Lua scripts can crash the device running the game. Garry's mod is quite a famous game with a Lua interpreter. Since, according to you, nothing can be done to solve this problem, Lua code that fills the memory would crash the device running GMod.

Yet it doesn't. Unlike you, the developers of Garry's mod are competent enough to understand that Lua scripts should not have any power beyond the game, since that's a huge security risk. Any exploits found where Lua scripts do have such powers, are fixed ASAP. As a simple result of this, filling the memory with a Lua script might crash Garry's mod, but NEVER EVER will it crash the entire device.

We're not asking you to solve the damn halting problem here. We're not asking you to make it impossible to make infinite loops. We're asking you to take your damn responsibility to fix a serious exploits that give modders the ability to crash an entire device.

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: trying to make a mod, accidentally crashed my whole computer

Post by prg »

FPtje wrote:Your incompetence is preventing you from seeing the underlying issue here, more importantly, you don't seem to understand who's responsible for what. The underlying issue is not Lua developers creating inefficient mods. The underlying issue is the game being so shit at dealing with this that it crashes not only the game, but the entire device.
Maybe you should fix your operating system if a userspace process requesting memory is able to bring it down completely.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

Divran
Inserter
Inserter
Posts: 47
Joined: Wed Jan 14, 2015 9:13 pm
Contact:

Re: trying to make a mod, accidentally crashed my whole computer

Post by Divran »

prg wrote:
FPtje wrote:Your incompetence is preventing you from seeing the underlying issue here, more importantly, you don't seem to understand who's responsible for what. The underlying issue is not Lua developers creating inefficient mods. The underlying issue is the game being so shit at dealing with this that it crashes not only the game, but the entire device.
Maybe you should fix your operating system if a userspace process requesting memory is able to bring it down completely.
Well you're not wrong, but it's not like microsoft is going to listen.

Post Reply

Return to “Modding help”

Who is online

Users browsing this forum: Honktown