After upgrading to Asterisk 18, Moved Temporarily causes two writes to CDR

Hello, similarly to my post with PJSIP issues, the problem I’m facing a is problem with one OpenSIPS server returning 302 Moved Temporarily. Using SIP, the CDR is being duplicated, one with disposition NO ANSWER, other with the real disposition.

What is strange is that this same configuration worked on older Asterisk servers (versions ranging from 1.8 to 11), I literally copied the configuration files from an Asterisk 11 server to Asterisk 18. I expected dozens of messages of deprecated features, but everything working the same way.

Dialplan:

[real-dial]
exten => _+X.,1,NoOp()
same => n,ResetCDR(v)
same => n,NoOp(LCR: ${CALLERID(num)} to ${EXTEN})
same => n,AGI(lcr.php,${EXTEN},"${gateways}")
same => n,Set(gateway=0)
same => n(tryGateway),Set(gateway=$[${gateway} + 1])
same => n,GoToIf($["${${gateway}_gateway}" = ""]?fail)
same => n,Dial(SIP/${dial_format_${gateway}}@${${gateway}_gateway},30,Tr)
same => n,GoToIf($["${DIALSTATUS}" = "CHANUNAVAIL"]?tryGateway)
same => n,GoToIf($["${DIALSTATUS}" = "CONGESTION"]?tryGateway)
same => n(fail),Verbose(1,${STRFTIME(${EPOCH},UTC,%c)}: ${CALLERID(num)} to ${EXTEN} failed with ${DIALSTATUS})
same => n,HangUp()

exten => h,1,Set(CDR(server)=${SERVER})
same => n,Set(CDR(audio)=${CHANNEL(audionativeformat)})
same => n,Set(CDR(QOSsrc)=${RTPAUDIOQOS})
same => n,Set(CDR(QOSdst)=${RTPAUDIOQOSBRIDGED})

The lcr.php calculates the cost of each gateway, then returns them in order to try dialing each one of them, returning the numbers in the correct format for each gateway.

There is nothing manipulating the CDR before the real-dial’s ResetCDR(v) in the dialplan.

The CDR from Asterisk 11:

"100","8100","+14423105636","real-dial","""8100 Test"" <8100>","SIP/8100-00000000","SIP/172.16.0.3:5060-00000002","Dial","SIP/+14423105636@OSIPS,40,Tr","2019-09-13 18:19:01","2019-09-13 18:19:04","2019-09-13 18:19:11",10,7,"ANSWERED","DOCUMENTATION","1568398741.0",""

The CDR from Asterisk 18:

"1","22200","+14423105636","real-dial","""Test"" <22200>","SIP/22200-00000008","SIP/OSIPS-00000009","Dial","SIP/+14423105636@OSIPS,40,Tr","2022-09-19 16:49:16",,"2022-09-19 16:49:16",0,0,"NO ANSWER","DOCUMENTATION","1663616956.13",""
"1","22200","+14423105636","real-dial","""Test"" <22200>","SIP/22200-00000008","SIP/172.16.0.3:5060-0000000a","Dial","SIP/+14423105636@OSIPS,40,Tr","2022-09-19 16:49:16","2022-09-19 16:49:19","2022-09-19 16:49:22",5,3,"ANSWERED","DOCUMENTATION","1663616956.13",""

It’s not writing the first entry and then writing the second (at least the first entry is not in the database while I’m in call), both CDR entries on Asterisk 18 seem to be written in the moment the call ends.

I tried using cdr set debug on, but it seems the older versions of Asterisk don’t have it, so I was unable to see more differences in the behavior.

The OpenSIPS gateway’s SIP configuration:

[OSIPS]
type=peer
host=172.16.0.3
port=5063
directmedia=yes
insecure=invite,port
description=OSIPS
qualify=yes
sendrpid=yes
nat=no
promiscredir=yes
allow=!all,g722,alaw,ulaw,gsm

Important: I know SIP is deprecated: migrating from 1.8-11 to 18 using SIP is an intermediate step. The end goal is PJSIP in real time.
Right now, the CDR issue is the blocker to the migration from 1.8-11 to 18 using SIP.

Is there a way to avoid the duplication in the CDR when 302 Moved Temporarily is received?

CDRs were fundamentally rewritten years ago at this point. The current spec is on the wiki[1]. They can, and will, produce more than one CDR for a call.

[1] https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+CDR+Specification

Right. So, with multiple CDR entries being the expected behaviour, then we’ll treat them. Fortunately, it’s known which gateways are issuing the 302.

One thing I have noticed in the wiki post is that, apparently, the example with the 302 is missing in the Wiki page. At least, there is the text:

Alice calls into Asterisk, which dials Bob's SIP desk phone. Bob is on vacation, and the SIP phone returns a "302" and redirects Asterisk to dial his SIP mobile

But there are no CDR logs for that.

The page doesn’t cover every possible case.