This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Hawk777's profile picture

[1.3] Infinite threads

Started by Hawk777, 29 February 2012 - 02:06 AM
Hawk777 #1
Posted 29 February 2012 - 03:06 AM
The JavaDoc for org.luaj.vm2.lib.CoroutineLib states that:

However, coroutines that are yielded but never resumed to complete their execution may not be collected by the garbage collector.

I believe this problem affects ComputerCraft. Every time I boot up a ComputerCraft computer, the Java process gains three threads (it's easy to see in Linux; just go into /proc/<pid>/task and run "ls"). Shutting down the computer doesn't terminate those threads, nor does even destroying it. More problematically, turning the computer on again starts another three threads. That means that just be rebooting a computer over and over, one can create infinite native threads, which can rapidly exhaust resources. This might be rather difficult to fix, but it's a bug nonetheless.
Liraal #2
Posted 29 February 2012 - 06:30 AM
Are you saying that:

--startup
while true do
os.reboot()
end
would crash any computer running CC?
Hawk777 #3
Posted 29 February 2012 - 07:47 AM
Darn right that's what I mean. The loop is actually not necessary because of course the startup file runs on each boot, so you get an implicit loop anyway. In a minute or two I got up to 1402 (over fourteen HUNDRED) threads running in my Java process, and then it exploded with:


org.luaj.vm2.LuaError: thread: java.lang.OutOfMemoryError: unable to create new native thread
stack traceback:

(yes, there was actually NO backtrace there)
Hawk777 #4
Posted 29 February 2012 - 07:48 AM
Interestingly Minecraft actually seems to be working not too badly after this; I guess Linux's scheduler is happy to keep fourteen hundred threads sleeping without any difficulty. But you can't boot any CC computers any more, not even brand new ones; they all spit the same OutOfMemoryError.
Casper7526 #5
Posted 29 February 2012 - 11:14 AM
Moved to bug forum.
TheVarmari #6
Posted 29 February 2012 - 01:34 PM
Are you saying that:

--startup
while true do
os.reboot()
end
would crash any computer running CC?
When I did it…
My MC world corrupted somehow.
Liraal #7
Posted 29 February 2012 - 01:36 PM
uh… sorry? :unsure:/>/>/>
Cloudy #8
Posted 15 March 2012 - 12:15 PM
I think it's worth pointing out that the thread creation and clean up has been improved due to updating the version of LuaJ.
FuzzyPurp #9
Posted 15 March 2012 - 07:26 PM
I think it's worth pointing out that the thread creation and clean up has been improved due to updating the version of LuaJ.

So is it safe now? meaning good enough to add CC back to GodCraft? right now CC will mess up servers eventually over time.
Cloudy #10
Posted 16 March 2012 - 01:17 AM
Most server owners probably wouldn't notice the issue (I've spoken to a couple who haven't noticed any issue). However there is still the small matter of 3 threads which do not appear to get closed. However these threads do not use much (probably not any) processing time and the only limits on threads are imposed by a system - but it won't cause any software or hardware damage.
Casper7526 #11
Posted 16 March 2012 - 03:07 AM
Heh, bigger server's notice this problem and it makes CC unusable. We've had to remove CC from godcraft because of it specifically. Dan needs to address this issue ASAP.
francogp #12
Posted 16 March 2012 - 12:41 PM
Is this solved in 1.31?
Casper7526 #13
Posted 16 March 2012 - 12:50 PM
No. Each computer will generate 3 threads everytime it's started. The threads don't take up very much memory or processing power (like .001%) but the problem lies in the fact that you can only have so many open threads within a program before it will crash.
francogp #14
Posted 16 March 2012 - 12:52 PM
Mmm… I think that this should have TOP priority for the next release
FuzzyPurp #15
Posted 16 March 2012 - 09:49 PM
It should have TOP priority right now!
Wolvan #16
Posted 19 March 2012 - 12:00 AM
Is this standard java or lua stupidness or has it to do with CC itself now? I don't really understand it :D/>/>
Casper7526 #17
Posted 19 March 2012 - 03:09 AM
It's a mix between dan's code and luaj code.
Cloudy #18
Posted 19 March 2012 - 02:05 PM
Just to let you know - dan is actively working on it. Computers now shut down all the threads correctly when they are turned off. Of course, there is still work to do, but he's on the case!
Wolvan #19
Posted 20 March 2012 - 02:19 PM
Just to let you know - dan is actively working on it. Computers now shut down all the threads correctly when they are turned off. Of course, there is still work to do, but he's on the case!
Great news! That will make my server less lagging :D/>/>
Hawk777 #20
Posted 30 April 2012 - 03:09 AM
This bug is now fixed; thanks Dan! The garbage collection system seems to be working; shutting down or rebooting a computer immediately destroys all the threads for its coroutines, and even if neither of the above happens, coroutines that are no longer reachable (either due to the program being terminated or simply by having their handles dropped on the floor) are destroyed after about 30 seconds. Perfect solution!