Hanging bug with ClearAllChildren

The Bug

If you attempt to call Instance:ClearAllChildren() on an instance in the same window that a descendant is being parented to said instance, the client hangs itself on a while loop.

Repro

local f = Instance.new("Folder")
f.ChildAdded:Connect(function ()
	f:ClearAllChildren()
end)

Instance.new("Folder",f) -- X_X

Probable Cause

Under normal circumstances, trying to destroy an object while its being parented to another object throws this warning in the output:

I suspect that ClearAllChildren is just doing some while (!children.empty()) loop without acknowledging this soft write-lock to the Parent property, so it gets snagged on that loop and never escapes, causing Roblox to hang.


Credit to @moded for the discovery,
He asked me to write a bug report because "[he's] bad at writing bug reports" (lol).


9 Likes

It’s been 5 years, and still no review for this bug. After searching for the exact error, I got to debug my code after a long time and acknowledged it was this. Now, this issue is still occurring, and it’s essential for my code to implement this behavior. If it gets fixed, it will run without any flaws. Hope this gets reviewed, as I bumped this, and gets fixed asap. Thanks.

1 Like

Deferred events seem to be the long term strategy to fix this and other related issues.

1 Like