[Home]

Summary:ASTERISK-13181: Memory usage increase when using SUBSCRIBE + vars defined in sip.conf
Reporter:marvinek (marvinek)Labels:
Date Opened:2008-12-09 04:39:50.000-0600Date Closed:2008-12-16 09:56:41.000-0600
Priority:MajorRegression?No
Status:Closed/CompleteComponents:Channels/chan_sip/Subscriptions
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) gxp-setup.txt
( 1) sip.conf
Description:I have a peer defined in sip.conf with pre-set variables (see excerpt bellow)
and subscription enabled for that peer. I can see ( by memory show summary ) that  all variables get allocated again with each subscribe request from the phone. These allocations do not get ever released until phone is restarted an re-registers (propably with different session id ?). This results in asterisk eating up all memory. I can reproduce this with Grandstream GXP-2000 , Linksys SPA96 and asterisk Releases 1.4.11, 1.4.22    

memory show ... shows increasing allocations in config.c
When I remove pre-defined vars from sip.conf problem disappears.

 

****** ADDITIONAL INFORMATION ******

sample entry in sip.conf
[28];    
host=dynamic
username=28
secret=xxxx
type=peer
context=from-inner
dtmfmode=info
call-limit=2
qualify=2000
allowsubscribe=yes
notifyhold=yes
notifyringing=yes
subscribecontext=hints
pickupgroup=1
callgroup=1
setvar=OUT_BLOCK_ACTION=none
.. more vars here ...
Comments:By: Russell Bryant (russell) 2008-12-09 16:47:41.000-0600

From a quick look at the code, I don't see anything obviously wrong.  However, I did verify that it is expected that the variables will get duplicated for every active SIP session.  However, when the dialog gets destroyed, that memory should get free'd.

Does it appear to you that this memory usage is increasing, even if the number of active dialogs in "sip show channels" goes down?

By: marvinek (marvinek) 2008-12-10 01:41:31.000-0600

Yes, I could see number of channels relevant to what on would expect i.e. acive   sip dialogs, this is not increasing in time. If I enter "sip show channel [TAB]"  I get a list of channels equal to number_of_registrations+number_of_subscribes.  This count is also not increasing. So the short answer is yes.

By: Russell Bryant (russell) 2008-12-11 14:14:33.000-0600

I have assigned this to blitzrage for some assistance in reproducing the issue.

By: Leif Madsen (lmadsen) 2008-12-11 15:12:10.000-0600

I can't reproduce this issue on my virtual machine. I'm using your peer configuration, and when I start Asterisk I get this:

*CLI> memory show summary config.c
      148 bytes in 2 allocations in function 'append_mapping' of 'config.c'
      864 bytes in 9 allocations in function 'inherit_category' of 'config.c'
     2160 bytes in 15 allocations in function 'ast_category_new' of 'config.c'
    18249 bytes in 197 allocations in function 'ast_variable_new' of 'config.c'
      120 bytes in 3 allocations in function 'ast_config_new' of 'config.c'
21541 bytes allocated in 226 allocations


Then I place some calls:

*CLI> memory show summary config.c
      148 bytes in 2 allocations in function 'append_mapping' of 'config.c'
      864 bytes in 9 allocations in function 'inherit_category' of 'config.c'
     2160 bytes in 15 allocations in function 'ast_category_new' of 'config.c'
    19719 bytes in 218 allocations in function 'ast_variable_new' of 'config.c'
      120 bytes in 3 allocations in function 'ast_config_new' of 'config.c'
23011 bytes allocated in 247 allocations


But then when I hang up the calls:

*CLI> memory show summary config.c
      148 bytes in 2 allocations in function 'append_mapping' of 'config.c'
      864 bytes in 9 allocations in function 'inherit_category' of 'config.c'
     2160 bytes in 15 allocations in function 'ast_category_new' of 'config.c'
    18249 bytes in 197 allocations in function 'ast_variable_new' of 'config.c'
      120 bytes in 3 allocations in function 'ast_config_new' of 'config.c'
21541 bytes allocated in 226 allocations

By: Leif Madsen (lmadsen) 2008-12-11 15:12:25.000-0600

btw: doing this on 1.4.22 as reported

By: Leif Madsen (lmadsen) 2008-12-11 15:15:35.000-0600

Can you show us exactly what your sip.conf peer looks like? (please don't strip anything out, attach as a separate file if necessary).

How many lines of setvar are being used on each peer entry?

By: Russell Bryant (russell) 2008-12-11 15:16:45.000-0600

You will see variable allocations for each of the following:

1) each peer and user from sip.conf when it gets loaded into memory from your configuration

2) each SIP dialog associated with these peers (including registrations and subscriptions)

3) each Asterisk channel for calls from the associated peers/users

I would expect to see the associated memory usage go up as there are active sessions going.  The question is whether you're seeing expected memory usage or a real leak.

It's certainly possible to optimize the memory used here, but this is what we have today in 1.4.

By: marvinek (marvinek) 2008-12-12 04:59:55.000-0600

OK, I will prepare detailed description how to reproduce this situation. That is something should have start with.

By: marvinek (marvinek) 2008-12-15 10:58:21.000-0600

Sorry for the dealy. As explained in original description, there is NO problem with call setup and cleanup. The problem is with SIP SUBSCRIBE message processing - this means when I enable BLF keys on the phone and the phone (peer) has defined vars in sip.conf(see attached sip.conf and gxp-setup.txt).

When register expire-time is set as low as 1 minute you can easily see memory increase each 60 seconds and count of new allocations = number of vars defined for peer. This is beacuse ... with each registration phone sends as many subscribes as is a number of BLF key activated. So no calls needed to see the problem.

Linksys962 has separate timeout for subscribe . So with this phone I could see that memory consumption increase is related only to SUBSCRIBE message and not to REGISTER message alone.

When the phone's BLFs are not able to subscribe (i.e. wrong hint extension or context ) memory is not affected.

I understatnd that memory usage goes up while sip dialog is running but should go down when this is finished which is not happening in this case.

I am ready to give you an root acces to my test setup



By: Russell Bryant (russell) 2008-12-16 09:05:56.000-0600

Thanks for the information.  I'll set up some subscriptions on my test box and see if I can reproduce it.  I'll let you know if I have trouble, and if so, access to your setup would be much appreciated.

Thanks for your help and patience!

By: Digium Subversion (svnbot) 2008-12-16 09:56:40.000-0600

Repository: asterisk
Revision: 164672

U   branches/1.4/channels/chan_sip.c

------------------------------------------------------------------------
r164672 | russell | 2008-12-16 09:56:40 -0600 (Tue, 16 Dec 2008) | 11 lines

Fix a memory leak related to the use of the "setvar" configuration option.

The problem was that these variables were being appended to the list of vars
on the sip_pvt every time a re-registration or re-subscription came in.
Since it's just a waste of memory to put them there unless the request was an
INVITE, then the fix is to check the request type before copying the vars.

(closes issue ASTERISK-13181)
Reported by: marvinek
Tested by: russell

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=164672