Search code examples
freeswitch

FreeSWITCH: Wrong number of tries with originate_retries


The documentation for originate_retries says

Number of retries before giving up on originating a call (default is 0).

Because of this I would expect that:

  • originate_retries=0 = 1 call
  • originate_retries=1 = 2 calls (1 try and 1 retry)
  • originate_retries=2 = 3 calls (1 try and 2 retries)
  • originate_retries=3 = 4 calls (1 try and 3 retries)

But in my testing I get:

  • originate_retries=0 = 1 call
  • originate_retries=1 = 1 call
  • originate_retries=2 = 2 calls
  • originate_retries=3 = 3 calls

My originate command is:

originate{originate_timeout=5,originate_retries=<X>,originate_retry_sleep_ms=5000}user/662 &park()

And my FreeSWITCH version is:

FreeSWITCH Version 1.10.2-release-14-f7bdd3845a~64bit (-release-14-f7bdd3845a 64bit)

Am I doing something wrong here, do I understand the documentation wrong, or is the problem in freeswitch / the freeswitch documentation?


Solution

  • In Freeswitch source file switch_ivr_originate.c you can see implementation of this.

    Variable retries is initialized with value of 1.

    When you originate call it will check if value is greater than 0 and less than 101.

    if ((var_val = switch_event_get_header(var_event, "originate_retries")) && 
        switch_true(var_val)) {
           int32_t tmp;
           tmp = atoi(var_val);
           /* allow large number of retries if timeout is set */
           if (tmp > 0 && (retry_timelimit_sec > 0 || tmp < 101)) {
               retries = tmp;
           } else {
               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
                          "Invalid originate_retries setting of %d ignored, value must be 
                           between 1 and 100\n", tmp);
        }
    }
    

    So if you set originate_retries=0 it will actually be set to 1.

    And at last, it will execute originate loop retries times.

    for (try = 0; try < retries; try++) {
    ...