Getting below exception and system came out form asterisk -r

channel.c:970 __ast_channel_alloc_ap: Channel allocation failed: Refusing due to active shutdown
chan_sip.c:7781 sip_new: Unable to allocate AST channel structure for SIP channel
channel.c:5681 __ast_request_and_dial: Unable to request channel SIP/TS09876

Please help me what could be the reason also I want to share that I have applied a failover code means if the number of call will cross 240 calls then new calls will dialed from other server

exten => _475460XXXXXXXXXX,1,NoOp(callstart)
exten => _475460XXXXXXXXXX,n,Set(ph=${EXTEN})
exten => _475460XXXXXXXXXX,n,Dial(DAHDI/g0/${EXTEN:5},M(obtransfer^1)To)
exten => _475460XXXXXXXXXX,n,Goto(s-${DIALSTATUS},1)

exten => s-CONGESTION,1,set(CALLERID(num)=${RAND(1246613568,1246613597)})
exten => s-CONGESTION,n,Dial(SIP/${ph},To)

exten => s-CHANUNAVAIL,1,set(CALLERID(num)=${RAND(1246613568,1246613597)})
exten => s-CHANUNAVAIL,n,Dial(SIP/${ph},To)

That’s because you requested Asterisk to shut down.

No…asterisk came out automatically and when I type asterisk -r it throw an error unable to connect asterisk
got the below waring as well

ERROR[1333][C-000022f7]: astobj2.c:148 INTERNAL_OBJ: user_data is NULL
chan_sip.c:25791 handle_request_invite: Call from ‘PW05133’ ( to extension ‘225’ rejected because extension not found in context ‘phones’.

and can you help with the code written for failover

That was the important information missing from the original report.

Apart from making sure you have the latest version (which version do you have?), if you don’t have Linux systems programming knowledge, which it appear to be the case, all I can really suggest is enabling thread debugging, as described in

With systems programming experience, I would advice setting a breakpoint on the code that produces that message and taking a backtrace when the breakpoint is trigged.

As you should be aware, the safe_asterisk script will automatically restart Asterisk if it terminates abnormally. However the design of a complete failover solution is way beyond the scope of a free, peer support, forum, like this.

is there any limit of maximum channels over asterisk single calling server??

It generally happens because of a bug. I suggested thread debugging because the bug may be related to failing to use locks properly.

That’s why it is important to have the latest version of Asterisk (more strictly the latest sub-version of a currently fully supported version).