Calls being answered and then disconnected after several seconds


I am looking for some help with a problem I have been debugging for several days now.

For a new project, we decided to try AWS Lightsail and install the latest Asterisk there. I am using Asterisk 20.4 as it was the latest at that time. It’s running on their Amazon Linux 2023 image which is RedHat based distribution.
The installation went almost smoothly and we got it up and running. Now we got to the implementation of the business logic in the Asterisk dial plan and we found a show stopper.

Every incoming calls gets disconnected after a certain amount of seconds. I am not saying exact seconds for all calls because it depends on the DID which received the call. We are using as the VoIP provider.
Example (note: the call is always answered by the Asterisk and then the counter begins):
If a call is received by a Swedish DID, the call is being dropped after exactly 60 seconds.
If a call is received by a Belgium DID, the call is being dropped after exactly 10 seconds.
The same issue occurs for all DIDs, no matter the country, just the drop timeframe is different.

That lead me to the conlusion that it may be an issue on the side so I had several technical conversations with them. We did traces from ours and their side and they said there is nothing wrong on their side. They said that the issue is most probably related to wrong inbound routes on the machine.
Lastly, we did a test with a new subaccount registered on a softphone and one of the DIDs attached to the same subaccount - the call is received, answered and NOT being dropped. In other words - working as expected. That concluded the issue must be in the Asterisk box.

I am pasting the latest configuration that I have tested with. I will describe below the things I have tried (if I can remember them all):

Since I am a new user and cannot upload files, I sending pastebin for the PJSIP log from the CLI logger here (the only hidden part is the caller phone number and the subaccount ID as in the settings):

The things I have tried:
– Initially I thought Lightsail is behind NAT but it looks like it is not. I tried playing with a lot of NAT settings + setting the local IP in the config.
– Changed our Asterisk port from the custom one we wanted back to 5060 (we read an article here that could be the issue)
– Lightsail firewall settings allow communication on both TCP and UDP 5060 although the asterisk is running only on TCP
– Tried Asterisk running on UDP connection instead of TCP
– We have 2 lightsail instances in 2 different continents - tried on both

Most probably I am missing something that I have tried but these are the main points.
ANY help would be much appreciated!

P.S. I am aware that EC2 is the preferred instances for AWS but if it is possible to run it on Lightsail, that would be perfect for us.

P.S.2. Outgoing calls are failing as well, I would assume the reason is the same. Again, the hangup cause is Normal Clearing as if I hung up the phone.

I am not sure exactly what you mean by this. Do you mean that the initial extension handling the call is in the form of an E.164 number for Sweden? That’s a function of the dialplan, and the only way the dialplan would cause an early termination would be if there was very specific, used provided, code to do that, so we would need to see the diaplan.

Essentially, every other interpretation would be strongly dependent on the provider’s behaviour.

Other possible interpretations are relate to the PSTN number being used to access the far side of the provider, or the choice of provider you use for your Swedish PSTN numbers.

Although I in DID definitely mean Incoming, some people also use it to refer to the default caller ID associated with outgoing calls on a particular provider account.

Inbound routes are a FreePBX created construct. In Asterisk they are implemented by the initial extension in the contexts used for calls from providers.

You seem to have screen-scraped your logs, which means there is no timing information. You need to enable the full log and then copy from /var/log/asterisk/full

The first call is terminated by the provider. Given that you aren’t sending any media, that may well be because of the lack of media. I believe there are options to send silence media, which may be more acceptable, when there is no media source.

Hello david551,

You are a miracle worker, honestly! Never would it have crossed my mind that the silence could be a problem!

I read your reply to my thread and I re-worked my dialplan just a bit to showcase what you requested. Once I tested it with a recording playing back all the time, it actually worked! Anyhow, I guess it would benefit someone in the future if we find the root cause in my dialplan.
The one that is working is (on loop recording):

; Make sure to include inbound prior to outbound because the _NXXNXXXXXX handler will match the incoming call and create a loop
include => voipms-inbound
include => voipms-outbound

exten => _NXXNXXXXXX,n,Hangup()
exten => _011.,1,Dial(PJSIP/${EXTEN}@voipms)
exten => _011.,n,Hangup()
exten => _00.,1,Dial(PJSIP/${EXTEN}@voipms)
exten => _00.,n,Hangup()

; inbound context example for your DID numbers, do not add the number 1 in front

exten => 3253281339,1,Goto(from-did,did,1) ;that’s the DID I am calling from my mobile phone

exten => did,1,Set(__DIRECTION=INBOUND)
exten => did,n,Set(OWNIP=localhost.localdomain)
exten => did,n,Set(KEEPCID=${CALLERID(num)})
exten => did,n,Set(DID=${CALLERID(dnid)})
exten => did,n,Set(call_id=0)
exten => did,n,Goto(answer-start,s,1)

exten => s,1,Answer(500)
;exten => s,n,Wait(5000000)
exten => s,n,Set(IVR_MSG1=welcome)
exten => s,n(playbackWelcomeMsg),Playback(${IVR_MSG1})
exten => s,n,Goto(s,playbackWelcomeMsg)

Let me know if you want to see a trace of a working call - I was dying for it till a few minutes ago. :slight_smile:
I will not be sending any more SIP traces because apparently it works in AWS Lightsail!

Now getting to the dialplan that is not working - I am trying to record the call after the welcome msg:
exten => s,1,Answer(500)
;exten => s,n,Wait(5000000)
exten => s,n,Set(IVR_MSG1=welcome)
exten => s,n(playbackWelcomeMsg),Playback(${IVR_MSG1})
;exten => s,n,Goto(s,playbackWelcomeMsg)
exten => s,n(waiting),Wait(1)
;exten => s,n(waitingfornoise),WaitForNoise(100,1)
exten => s,n(recordAgain),Record(/var/www/html/v1/incoming_calls/${KEEPCID}_1:wav,1,30,q)

The first problem seems to be that the Record function doesn’t produce an error message on certain linux permissions (not sure which exactly). If the asterisk’s user does not have access at all to the folder, it produces an error. If it has read access to the folder (my assumption for now), it doesn’t produce an error and I am left with the impression that the recording is actually saved. This one should be investigated further.

It will take me quite a lot of time to show you the rest of the dial plan but I can summarize:
– based on some input, the dialplan sends several CURL requests one after another - and most probably this is where the ‘silence’ problem kicks in because the requests take between 3 to 12 seconds.

If we assume that the silence is the problem - ok, that makes sense for the Belgium DID which gets it’s call disconnected on the 10th second. What about the Swedish DID? It gets disconnected at around 1 min. Maybe it is related to the HPLMN I am using and how it gets to the VoIP’s DID (through which gateways).

You mentioned that there is a way to play some silence media. What I have come across so far is Playback(silence/1) (where ‘1’ is the number of seconds. But this is not done in parallel but rather in order. I want something to ‘keep alive’ the call while the CURL requests are ongoing. Any thoughts?

Again, thank you very much! I am much closer to the solution now.

After several days, I found the right solution to my problem! The problem was that a call is being disconnected after several seconds if there is no audio stream. In my case, it happens in both directions - when the caller is speaking for a long time without interruption (and being recorded with Record() func), and when the asterisk is handling logic for a long time, in my case 10+ seconds.

The solution is fairly simple:

  1. Use Local channels (Dial(Local…)) to handle the external logic (calling 3rd party services and stuff). This also helps with debugging.

  2. In order to keep the audio stream ongoing, I have to play some audio no matter if the user is speaking or asterisk is running some CURL requests. The MusicOnHold() func is great but it stops the dialplan. By chance, I found that there is another func called StartMusicOnHold() which doesn’t stop the dialplan and continue its execution! It does not persist through channel switching (point 1 above) but you can start it in main and sub (local) channel independently. Also, it can be stopped with the same command StopMusicOnHold().
    exten => s,n,StartMusicOnHold(silence)

  3. In my case, in order to have a ‘silence’ music playing almost all the time, I had to have a recording of ‘silence’ and then modify the musiconhold.conf to include a class of [silence] and where that .wav file is stored. In my case, that is:
    mode = files
    directory = moh/silence

which effectively gets to /var/lib/asterisk/moh/silence/silence.wav

Again, thank you david551, you pointed me in the right direction!

I hope this helps someone in the future.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.