Gateway scripts stalling

Perhaps it's related to your database issue: Can I use a script to reconnect a database?

Maybe solving that will solve both.