Try to find the exact place where it is failing and then try to get the solution for it.
Hope it will be helpful to you.
Pawan Awasthi(DNS MVM)
+91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
In your function somewhere it should end. If it reaches it should stop rec function.
If you are trying to pars XML it in the rec function you should check whether it is last node. If last node u should stop your rec and continue to next node.
Likewise you have to handle in your requirement.
Direction is important than speed