Asterisk 16 w/PJSIP DNS SRV Failover

I’ve got PJSIP configured like this:


The following DNS records are configured

10 100 "S" "SIP+D2U" ""

10 100 5060
10 100 5060

And it seems to work! Asterisk switches between and 101 pretty evenly.

However, when I do a failover test, taking one of those servers offline, Asterisk still tries it (for something like 20-30 seconds), before trying the other one, and it doesn’t appear to “remember” that this particular server was offline.

I’m wondering if there are some obvious settings that controls this behavior?

In particular I’d like to reduce the number of seconds Asterisk attempts to connect, and well, if Asterisk could be configured to remember that this particular server was offline for the next say, 5 minutes or something like that, that would be awesome as well.

The only option which controls that would be Timer B, configurable in the system section of pjsip.conf. It defaults to 32 seconds.

There is no state maintained or knowledge about targets like that to know when the target is offline. Resolution and usage occurs when it is used.

Fair enough - reducing Timer B is okay for me. These Asterisk boxes only ever communicate to peers within their same LAN.

Are there any alternative ways of doing failover in this fashion? The only thing I’ve sort of been able to find is using DNS NAPTR/DNSSRV like I am here

You could have individually configured endpoints with individually monitored AORs that each have an IP address. That’s the first thing that comes to mind. The failover works best with connection oriented protocols, as they can be determined faster if unreachable or not.

1 Like

Having multiple endpoints would require me to do failover in the dialplan code right?

Yes, it would. Those are the current options available.

No worries. I should look into if using TCP or TLS is possible anyway.

Just to confirm: If using TCP, Asterisk will use one connection per established sip call right, it’s not possible to reuse the same TCP connection for several SIP Dialogs?

PJSIP reuses connections across everything, it is not per-call.

Oh really? Excellent! One of the reasons we wanted to use UDP was to avoid potentially thousands of TCP Connections between these Kamailio boxes and the Asterisk boxes.

Thanks! :smiley:

PJSIP looks for existing connections based on transport type + IP address + port. So if it needs to send a packet to “TLS port 5061” then it’ll search for an active connection to there and if present use it.

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