Custom Context Extension Blocks

I’m having an issue with some custom context’s I created. They worked well for a while but now I am getting an asterisk error that I believe is related to having too much includes in my contexts.

[2017-05-16 13:30:31] WARNING[32615][C-00002516]: pbx.c:2461 pbx_find_extension: Maximum PBX stack exceeded

I’m trying to isolate certain extension blocks from being able to call one another. Ex 1XX cannot call anyone outside of the 1XX extension range, 2XX can only dial 2XX numbers without getting a “not in service” error.

I start with an extension block context that I set as the context to every extension in said range. It allows certain calls to go to from-internal and work like normal:

; Allows these extensions and these extension star codes
exten => _4XX,1,Goto(from-internal,${EXTEN},1)
exten => _*4XX,1,Goto(from-internal,${EXTEN},1)
include => template-firewall

That inherits/includes a general context that they all inherit/include. This is designed to allow 7+ digit dialing to go through along with some exceptions then block everything else.

; Allows 7 digit numbers and above
exten => _XXXXXX.,1,Goto(from-internal,${EXTEN},1)

; Allows Certian Special Numbers
exten => _911,1,Goto(from-internal,${EXTEN},1)
exten => _933,1,Goto(from-internal,${EXTEN},1)

; Denies All Regular Numbers
exten => _X.,1,Answer(10)
exten => _X.,n,playback(ss-noservice)
exten => _X.,n,Hangup()

; Allows Certain feature codes to dial through
exten => _[]2[789].,1,Goto(from-internal,${EXTEN},1)
exten => _[
exten => _[*]21XX.,1,Goto(from-internal,${EXTEN},1)

; Deny access to voicemails/Feature Codes
exten => *XXX,1,Answer(10)
exten => _*XXX,n,playback(ss-noservice)
exten => _*XXX,n,Hangup()
exten => *XXXX,1,Answer(10)
exten => _*XXXX,n,playback(ss-noservice)
exten => _*XXXX,n,Hangup()
exten => *XXXXX,1,Answer(10)
exten => _*XXXXX,n,playback(ss-noservice)
exten => _*XXXXX,n,Hangup()
include => from-internal

This was working well and didn’t mess up the BLF keys and dialing worked exactly as I wanted it to. Then I started getting the error:

[2017-05-16 13:30:31] WARNING[32615][C-00002516]: pbx.c:2461 pbx_find_extension: Maximum PBX stack exceeded

I think it is related to too many includes but I am having trouble getting anything else to work that doesn’t mess up BLF keys or work like this context does.

I’m relatively new at adding contexts to asterisk and I am wondering if I am doing this the proper way or if I am doing some overly elaborate method when there is a much better way of doing it that I don’t know about. Wouldn’t be the first time that happened.

Any advice or code critique?

Try setting “Disable -custom Context Includes” to yes in Advanced Settings.

1 Like

I tried that and I have not seen the error come back for a day and a half :D. I think it might be fixed.


So what does disabling that do? I read it has to do with some from-internal-custom context but we have never used that.

1 Like

When enabled, almost every single FreePBX generated context will #include a corresponding -custom context for users to add their own custom dialplan. Since most users don’t use any of these -custom contexts (and indeed, many are not usable anyway), disabling them will generally not have much of an effect, but will reduce the overall number of includes significantly.

1 Like

well that fixed the issue for a few days… I added 12 extensions and a ring group and now it’s back @_@.

Any ideas?

This only seems to happen to the extensions I have my custom context on. For the ones without my custom context they seem to work fine (from-internal). Thats why I wonder if there is an issue with my custom context but I don’t know how to diagnose it or fix it… If there is a better place for my custom contexts I could move/rebuild them and see if that helps.

We are having issues with this:

[2017-05-16 13:30:31] WARNING[32615][C-00002516]: pbx.c:2461 pbx_find_extension: Maximum PBX stack exceeded

We were having issues with it before but then we condensed 6 outbound routes into 1 and the warning went away for a while. We have been adding more ring groups and parking lots since then and it has returned. At one point when we added a single parking lot the warning occurred then when we removed it then the warning went away.

Right now I think we are a little above the border between when this happens and when it doesn’t happen. I asked on the asterisk forums and this is related to having includes go 128 levels deep. I’ve looked the best I can and I can’t tell how its possibly going that deep.

We have ~15 outbound routes, 60 parking lots, 138 ring groups, 13 queues, 103 time conditions, 90 announcements, 900 extensions (though only about 700 are actual phones).

It seems that adding another parking lot caused the issue to pop up again but why would another parking lot add another level of include depth? Looking at the dial plan it looks like it would increase the number of includes on the 5th level of includes but why does it add depth?

1 Like

Do you have custom contexts installed?

Thanks @jfinstrom this is a problem with custom contexts

The Custom Context module is not installed.

You’ve created custom contexts. The reason this pbx stack happens is with either custom contexts module. Or with improperly looping contexts. If you removed custom code you probably won’t have the issue anymore.

In the normal course of programming, people often write re-entrant code - this is code that calls itself either directly or indirectly. If you’ve added any custom code to your system, or if you’ve set up a call sequence that has no exit, you can blow the stack by calling the same routine over and over until you run out of heap space.

So - there are two possibilities:

  1. You’ve added a custom context that includes other contexts which then include your context.
  2. You’ve built in a loop in your system (e.g., an announcement that calls a destination that’s busy that calls the announcement as the “error” leg which calls the extension…)

Removing all of the “-custom” contexts can help you find the problem by narrowing the scope of your search down. You can also look at the “/var/log/asterisk/full” lot before the error message and figure out what loop you are in.

Note that the Custom Context module is something else completely different. It’s there to help you manage custom contexts, which can be added to your installation either by editing the -custom config files, or by certain additions to Asterisk that modify the system.

Update to anyone that finds this:

It wasn’t the custom context firewall that was the main cause of it, it added to it a tiny bit. It was our 60 parking lots and our outbound routes. Each parking lot and outbound route has an include in it and all of those includes added up to exceed the Maximum number of includes allowed, it appears to be a soft limit. We hit the absolute limit by adding a parking lot and it caused outbound calls to break. Deleting the parking lot allowed outbound calling again. We were able to add another parking lot by removing an outbound route.

So number of outbound routes + parking lots + modules can cause this.

There is a related issue here if you want to vote/watch it: