161 posts
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.
473 posts
Location
Poland
Posted 29 February 2012 - 06:30 AM
Are you saying that:
--startup
while true do
os.reboot()
end
would crash any computer running CC?
161 posts
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)
161 posts
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.
411 posts
Posted 29 February 2012 - 11:14 AM
Moved to bug forum.
67 posts
Location
Finland
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.
473 posts
Location
Poland
Posted 29 February 2012 - 01:36 PM
uh… sorry? :unsure:/>/>/>
2447 posts
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.
496 posts
Location
Harlem, NY
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.
2447 posts
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.
411 posts
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.
57 posts
Posted 16 March 2012 - 12:41 PM
Is this solved in 1.31?
411 posts
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.
57 posts
Posted 16 March 2012 - 12:52 PM
Mmm… I think that this should have TOP priority for the next release
496 posts
Location
Harlem, NY
Posted 16 March 2012 - 09:49 PM
It should have TOP priority right now!
378 posts
Location
In the TARDIS
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/>/>
411 posts
Posted 19 March 2012 - 03:09 AM
It's a mix between dan's code and luaj code.
2447 posts
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!
378 posts
Location
In the TARDIS
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/>/>
161 posts
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!