<!-- Kamailio Project uses GitHub Issues only for bugs in the code or feature requests. Please use this template only for bug reports.
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.
Note that an issue report may be closed automatically after about 2 months if there is no interest from developers or community users on pursuing it, being considered expired. In such case, it can be reopened by writing a comment that includes the token `/notexpired`. About two weeks before considered expired, the issue 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 pursuing the issue.
If there is no content to be filled in a section, the entire section can be removed.
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 BYE transactions keept increasing and were never freed.
#### Reproduction 1. Compile kamailio 5.8.5 and run it under no traffic, with default config 2. Connect 1 WSS client 3. Send INVITE with "Session-Expires" header from WSS client -> kamailio -> PBX (e.g. asterisk) 4. Wait for WSS client to refresh session in re-INVITE with another "Session-Expires" 5. Force kill WSS client and wait 6. PBX (asterisk) will send BYE to end session 7. kamailio replies "477 Unfortunately error on sending to next hop occurred (477/SL)" 8. kamcmd tm.list | grep BYE -> will see that transaction there is never freed
#### Debugging Data + Log Messages ``` DEBUG: tm [h_table.c:415]: build_cell(): created new cell 0x7f673e2552d0 INFO: <script>: [pdn60n9cob1j3j0doi36] MANAGE_BRANCH: New branch [0] to ....., BYE WARNING: tm [../../core/forward.h:217]: msg_send_buffer(): TCP/TLS connection for WebSocket could not be found DEBUG: tm [t_fwd.c:1566]: t_send_branch(): send to 169.132.91.64:1702 (5) failed WARNING: tm [t_fwd.c:1586]: t_send_branch(): sending request on branch 0 failed DEBUG: tm [t_funcs.c:358]: t_relay_to(): t_forward_nonack returned error -1 (-477) DEBUG: tm [t_funcs.c:376]: t_relay_to(): -477 error reply generation delayed DEBUG: sl [sl_funcs.c:564]: sl_run_callbacks(): execute callback for event type 1 ERROR: sl [sl_funcs.c:428]: sl_reply_error(): stateless error reply used: Unfortunately error on sending to next hop occurred (477/SL) DEBUG: dialog [dlg_hash.c:780]: dlg_lookup_mode(): ref dlg 0x7f673e5dbae0 with 1 -> 2 DEBUG: dialog [dlg_hash.c:784]: dlg_lookup_mode(): dialog id=6986 found on entry 2734 DEBUG: dialog [dlg_hash.c:1088]: dlg_unref_helper(): unref op on 0x7f673e5dbae0 with 1 from dlg_hash.c:1106 DEBUG: dialog [dlg_hash.c:1092]: dlg_unref_helper(): unref dlg 0x7f673e5dbae0 with 1 -> 1 ```
#### 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). -->
```

```
### Possible Solutions Tracked this down to this "#ifdef" that is defined inside the C file itself: https://github.com/kamailio/kamailio/blob/master/src/modules/tm/t_funcs.c#L3...
Solution 1: remove all the code related to TM_DELAYED_REPLY since it is anyway local to t_funcs.c file
Solution 2: t_release_transaction(t); /* kill it silently */ in case of TM_DELAYED_REPLY too
### Additional Information
* **Kamailio Version** - output of `kamailio -v`
``` all up to latest one ```
* **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 `lsb_release -a` and `uname -a`) -->
``` not relevant ```
Looking forward to do a PR for this but wanted to ask:
For Solution 1, any idea if TM_DELAYED_REPLY is really needed for something? Looks like very old code in "git blame" For Solution 2, noticed that a 2'nd 477 is sent for the same BYE: - first by tm module, before killing the transaction - second by sl module
miconda left a comment (kamailio/kamailio#4140)
I pushed a commit to change TM_DELAYED_REPLY to a modparam `delayed_reply`, because it has the purpose of allowing the config writer to send its own response in case of tm request processing/forwarding failures.
Can you try to use:
- https://www.kamailio.org/docs/modules/5.8.x/modules/sl.html#sl.f.send_reply_...
instead of `sl_reply_error()` in your config?
The case has to be handled somehow automatically, the above suggestions are more to figure out if that is the real issue, then code something for it.
Closed #4140 as completed.
stefan-mititelu-idt left a comment (kamailio/kamailio#4140)
Thank you for the advice! Using the other config function freed the BYE transaction for this scenario.