Internet watchdog

shaniyakov:
by that time the arduino stops searching for connection

It just a random suggestion as you have chosen not to provide any details of your setup, but it might be an idea to increase the time the arduino searches for a connection maybe ?