flaviogrossi created an issue (kamailio/kamailio#4399)

<!--
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.org/

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.org/

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

There is a memory leak in the pkg memory pool for the slow timer process when 
the dispatcher module is used and the OPTIONS probing is enabled (and some 
other seemingly unrelated configs are enabled).

In the reproduction section i'm attaching a basic configuration used to 
reproduce the leak.

It can be observed by repeatedly calling `kamcmd pkg.stats` and looking at the 
`real_used` field of the `slow timer` process, for example with `kamcmd 
pkg.stats | grep -B8 slow | grep real_used` (below in `Debugging data` a sample 
progression can be found)

I'm trying to dive in the sources, but in the meantime i can provide more 
details if needed.

### Troubleshooting

Enabling the memory debugging and executing `kamcmd cfg.set_now_int core 
mem_dump_pkg _PID_` the leak appears to be caused by these blocks of memory:

```
count= 17078 size=   8203200 bytes from core: core/parser/parse_from.c: 
parse_from_header(65)
count= 17078 size=    820192 bytes from core: core/parser/parse_addr_spec.c: 
parse_to_param(304)
```

Attaching gdb and dumping the used memory from the slow timer process reveals 
that the leaked memory  contains the OPTIONS sip message which is sent to probe 
for dispatchers (i don't have it right now but i can collect it again if needed)

Also, the bug cannot be reproduced anymore if any of these changes is made:
- the `onsend_route` is deleted from the configuration
- `log_prefix` is set to 0
- `use_dns_failover` is not enabled
- `$fu` is removed from the `log_prefix` configuration (e.g., replace it with 
`log_prefix=" to: $tu "`)
- the dispatcher ping is removed (from configuration, from the dispatcher list, 
etc.)

#### Reproduction

with the latest kamailio compiled from sources and started with 
`/usr/local/sbin/kamailio -P /var/run/kamailio/kamailio.pid -m 128 -M 12
`, the bug can be reproduced by just using the configuration found at 
https://pastebin.com/k5Uh6UfQ

That configuration is basically the default with with the following critical 
additions:
- `use_dns_failover=on`
- `log_prefix_mode=1`
- `log_prefix=" from: $fu, to: $tu "`
- `modparam("dispatcher", "ds_ping_interval", 2)` to have an high ping 
frequency to leak memory faster
- `modparam("dispatcher", "ds_probing_mode", 1)` to continuously send the 
OPTIONS
- the `onsend_route` at the end of the file (where the drop() is never actually 
executed, but it must be there)

at least one dispatcher configured in 
`/usr/local/etc/kamailio/dispatcher.list`, no need to have a reply or to be a 
reachable ip address:

```
1 sip:192.168.56.124:5060
```

#### Debugging Data

<!--
If you got a core dump, use gdb to extract troubleshooting data - full 
backtrace,
local variables and the list of the code at the issue location.

  gdb /path/to/kamailio /path/to/corefile
  bt full
  info locals
  list

If you are familiar with gdb, feel free to attach more of what you consider to
be relevant.
-->

```
# date && kamcmd pkg.stats | grep -B8 slow | grep real_used
Fri Sep 19 13:02:49 UTC 2025
        real_used: 2192352
# date && kamcmd pkg.stats | grep -B8 slow | grep real_used
Fri Sep 19 13:02:56 UTC 2025
        real_used: 2195360
# date && kamcmd pkg.stats | grep -B8 slow | grep real_used
Fri Sep 19 13:03:11 UTC 2025
        real_used: 2200592
# date && kamcmd pkg.stats | grep -B8 slow | grep real_used
Fri Sep 19 13:20:51 UTC 2025
        real_used: 2599072
```

#### Log Messages

Nothing relevant that i can see

#### SIP Traffic


### Possible Solutions


### Additional Information

Reproduced with kamailio 6.0.3 and confirmed to be present in the last master 
at the time of writing 8d00b20

* **Operating System**:

Not OS dependant, but tested both with the kamailio docker image version 6.0.3 
based on ubuntu noble and RockyLinux 10 with latest master


-- 
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/4399
You are receiving this because you are subscribed to this thread.

Message ID: <kamailio/kamailio/issues/[email protected]>
_______________________________________________
Kamailio - Development Mailing List -- [email protected]
To unsubscribe send an email to [email protected]
Important: keep the mailing list in the recipients, do not reply only to the 
sender!

Reply via email to