Couple of questions...

How does this script behaves on Test database?
Is this the first time this script runs against production?
... if not, has script changed since last succesful run?

Last but not least, have you taken a look at the function's code? ... what it does?

Check any piece of logic that may induce a never ending loop condition.