signalwire / freeswitch

FreeSWITCH is a Software Defined Telecom Stack enabling the digital transformation from proprietary telecom switches to a versatile software implementation that runs on any commodity hardware. From a Raspberry PI to a multi-core server, FreeSWITCH can unlock the telecommunications potential of any device.
https://freeswitch.com/#getting-started
Other
3.35k stars 1.38k forks source link

Dynamic gateway creation/deletion leads to leaks #1477

Open StefanYohansson opened 2 years ago

StefanYohansson commented 2 years ago

Describe the bug I am using a script to create gateways based on some users logging into an interface. The steps the script execute:

add user
    create directory file
    create gateway file
    reloadxml
    rescan profile
delete user
    delete directory file
    delete gateway file
    kill gateway
    reloadxml

The problem is the script executes these steps async and sometimes an add and delete can occur at the same time. This leads to sometimes a gateway being marked to deletion, it is deleted from the gateway list but if I enable sofia debug it is still sending registers.

To Reproduce Steps to reproduce the behavior:

  1. Using vanilla FS config in master branch
  2. Execute the script with parameters: python main.py 10 3 2 150
  3. enable sofia debug with sofia global siptrace on
  4. after script finishes check for REGISTERs being emitted for some gateways
  5. execute sofia status and confirm there's no gateway in the list

script parameters explanation: 10 new users per second 3 deleted every 2 cycles (every 20 users added, delete 3) 150 new users at total

Expected behavior After the script removes all the gateways, it should stop sending registers for that gateway.

Package version or git hash

Script: https://github.com/StefanYohansson/dynamic_gateway_directory_creator Way to execute: copy example.ini to config.ini and change paths to something like

[Freeswitch]
CliPath = /home/snotr/Projects/builder/out-docker-vm/freeswitch/bin/fs_cli
FsPath = /home/snotr/Projects/builder/out-docker-vm/freeswitch/etc/freeswitch
SipDomain = 192.168.1.69

and execute step 2 with python3.

dragos-oancea commented 2 years ago

so it's more than just memleaks, it's about a misbehaviour too ? My understanding is that it still sends REGISTERs towards the removed gw.

StefanYohansson commented 2 years ago

yes, it is more than a memory leak, the gateway is not visible via sofia status or any other sofia command but activating the siptrace on, I can still see ongoing REGISTERs to the REGISTRAR server.

In this example, the gateway is registering in an extension in the same FS but I can reproduce the same issue with a gateway registering elsewhere, it is this way for the sake of simplicity in reproducing the problem.