How do I handle retry logic for unreliable external resources?


It is quite common for an interface to use retry logic when encountering unreliable external resources. Such situations may include the following:

  • An unreliable database connection
  • An application that for some reason cannot listen on a port as directed
  • An application that returns a negative ACK due to its own resource issues

These, and other conditions, can be identified by the errors that occur. Some errors will indicate transitory problems which can be overcome with enough retries. Other errors could indicate fatal conditions requiring the interface to stop. Iguana gives you complete control over identifying errors and implementing your desired response.

How It Works [top]

The retry module used on this page is quite simple. The function retries the specified function call whenever an error occurs. By default a fatal error occurs if the retried function returns false, or you can supply an error function for custom error handling.

The takes various arguments like: The function to be called, the number of retries, pause (in seconds) and zero or multiple arguments for the function, etc. Also multiple returns from the function are supported.

Tip: In the real world we would probably not want to simply retry for all errors, some could considered fatal, and some might trigger different actions. The same applies to function returns.

The last page in this section explains how to customize the retry logic using an error function for both scenarios.

Additional Information [top]

We introduced the retry module, which can be used to retry any call that generates an error. Our examples show how to retry a database and also an LLP connection.

If you have any requirements not met by this script, please contact support at and we’ll see if we can help.

Leave A Comment?

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.