"Maimum re-entrancy depth (10) exceeded" lacks stack trace

Reproduction Steps
Run code that triggers the maximum re-entrancy error such as the following:

local function f(i)
	if i == 20 then
		task.defer(f, i + 1)


Expected Behavior
I expect Maximum re-entrancy depth (10) exceeded to include a stack trace so I know what code is causing the issue.

Tracking down the cause without a stack trace is a massive pain and leaves me wondering if the issue is even in my code.

Luckily, I was doing this in an isolated environment for running tests, so I just disabled each test one-by-one until I found the cause. Can’t say I’ll always be so lucky! If I encountered this on a live game with a massive codebase it would be practically impossible to find the cause!

Actual Behavior
Maximum re-entrancy depth (10) exceeded does not include a stack trace.


In some cases there is no workaround for this issue. For example, finding the cause of this error would be impossible in large codebases running into obscure edge-cases in live games.

Issue Area: Engine
Issue Type: Other
Impact: High
Frequency: Sometimes
Date First Experienced: 2022-03-03 00:03:00 (-06:00)
Date Last Experienced: 2022-03-03 00:03:00 (-06:00)


Thanks for the report! We’ll follow up when we have an update for you.


A better message is critical here because using the debugger will prevent the re-entrancy bug from occurring—a Heisenbug!

I was searching for recursion in my code when that wasn’t the problem at all, just that function 1 deferred 2, 2 deferred 3, and so on, where the same function was never deferred twice. I’d much rather see something like “task deferring repeatedly deferred more tasks 10 times”.

Tangentially, the ideal solution would be to entirely remove the re-entrancy limit from task.defer() and rely on script execution timeout. My code was reasonable.

Hey everyone, so sorry for the late response here. We’re working hard to improve our responsiveness to bug reports. Are you still experiencing this issue? If so, please let me know, and we’ll get this routed to the right people at Roblox.