Timeout (or not timeout) in SmartApp

I have a smartapp, which adds fairy large number of devices. The problem is that after about 10-12 seconds of execution, it shows “there was a problem processing your request. Please try again” and does nothing.
If it hit save again (which continue operation of device adding), it works correctly and adds devices.
I suspect this is some kind of timeout, however, there is nothing in log, which says that.
What is the problem? Is there some kind of timeout for SmartApp execution and if it is, how to enlarge it or alternatively, make it adding Devices asynchronously?

Thank you

Please read the Developer Docs:


  1. A single command in a SmartApp has a 20s execution limit.

  2. A SmartApp invocation has an overall maximum 40s.

Neither of these limits are changeable.

If you have a long loop in your SmartApp, break it into multiple invocations using chained runIn()'s