<!-- Kamailio Project uses GitHub Issues only for bugs in the code or feature requests. Please use this template only for feature requests.
If you have questions about using Kamailio or related to its configuration file, ask on sr-users mailing list:
* https://lists.kamailio.org/mailman3/postorius/lists/sr-users.lists.kamailio....
If you have questions about developing extensions to Kamailio or its existing C code, ask on sr-dev mailing list:
* https://lists.kamailio.org/mailman3/postorius/lists/sr-dev.lists.kamailio.or...
Please try to fill this template as much as possible for any issue. It helps the developers to troubleshoot the issue.
If you submit a feature request (or enhancement) add the description of what you would like to be added.
If there is no content to be filled in a section, the entire section can be removed.
Note that a feature request may be closed automatically after about 2 months if there is no interest from developers or community users to implement it, being considered expired. In such case can be reopened by writing a comment that includes the token `/notexpired`. About two weeks before considered expired, the item is marked with the label `stale`, trying to notify the submitter and everyone else that might be interested in it. To remove the label `stale`, write a comment that includes the token `/notstale`. Also, any comment postpone the `expire` timeline, being considered that there is interest in the proposed feature request.
You can delete the comments from the template sections when filling.
You can delete next line and everything above before submitting (it is a comment). -->
### Description
I followed the page 18~23 of this slide [20-Federico.Cabiddu-Kamailio-In-A-Mobile-World](https://www.kamailio.org/events/2015-KamailioWorld/Day2/20-Federico.Cabiddu-...) to implement suspension & push notification, it worked well on mobile devices.
However, callee might have several location records on some occasions, for instance, they forcibly quit the app or kill the browser, meaning they don't de-register, the location hasn't expired and still exists, but it is stale and unreachable, this makes `t_relay` failed (return code is -2 and didn't trigger failure_route) since Kamailio `lookup` the stale location rather than the new one as they get push notification, below are some part of logs.
``` ERROR: tm [t_fwd.c:484]: prepare_new_uac(): could not build request ERROR: tm [t_fwd.c:1764]: t_forward_nonack(): failure to add branches ERROR: <script>: not t_relay by INVITE -2 ERROR: <script>: check status code is 100 ```
The rest of Kamailio code triggers `sl_reply_error`, caller gets 500 and terminates.
### Expected behavior
When callee has several locations, even if some of them are stale, callee should not terminate the call and should find a valid location to ring the target.
#### Actual observed behavior
Caller finds invalid locations and gets 500 error msg.
#### Debugging Data
What I have tried 1. Run `suspend` when `t_relay` failed. ``` if (!t_relay()) { revert_uri(); route(SUSPEND); } ``` It doesn't work since `t_continue` still tries to recover the call with the stale location.
2. Run `append_branch` before `t_relay`. ``` if (!lookup("location")) { send_replay("100", "Trying"); route(SUSPEND); } else { append_branch($tu); t_relay(); ts_store(); $sht(vtp=>stored::$rU) = 1; xdbg("stored transaction [$T(id_index):$T(id_label)] $fU=> $rU\n"); } ``` This version of caller won't get 500 and terminate, but callee cannot finds the resumed call.
3. Use `t_load_contacts` and `t_next_contact`. ``` t_load_contacts(); while (t_next_contacts()) { xlog ("==== $ru\n"); } ``` t_next_contacts always return -2 (nothing to do), but I can see the new location via command `kamctl ul show`.
#### Log Messages
<!-- Check the syslog file and if there are relevant log messages printed by Kamailio, add them next, or attach to issue, or provide a link to download them (e.g., to a pastebin site). -->
``` (paste your log messages here) ```
#### SIP Traffic
<!-- If the issue is exposed by processing specific SIP messages, grab them with ngrep or save in a pcap file, then add them next, or attach to issue, or provide a link to download them (e.g., to a pastebin site). -->
``` (paste your sip traffic here) ```
### Possible Solutions
<!-- If you found a solution or workaround for the issue, describe it. Ideally, provide a pull request with a improvement. -->
### Additional Information
* **Kamailio Version** - output of `kamailio -v`
``` (paste your output here) ```
* **Operating System**:
<!-- Details about the operating system, the type: Linux (e.g.,: Debian 8.4, Ubuntu 16.04, CentOS 7.1, ...), MacOS, xBSD, Solaris, ...; Kernel details (output of `uname -a`) -->
``` (paste your output here) ```