Why Does Your SIP Call Hang Up at Exactly 32 Seconds?

The agent picks up, the customer explains the problem, both sides hear each other fine. Then,...

Ahmed Elbashier (Open-Source)8 min read0 kali dilihat
Why Does Your SIP Call Hang Up at Exactly 32 Seconds?

The agent picks up, the customer explains the problem, both sides hear each other fine. Then, mid-sentence, the call drops. You check the CDR: 32 seconds. The next failed call: 32 seconds. And the one after that.

A drop that lands on the same second every time is not a network glitch. It's a timer, and RFC 3261 tells you which one. The callee answered, but it never got the ACK for its 200 OK.

To check that quickly, I wrote a small tool, sip-ack-timeout-doctor. Give it a text SIP trace and, for each call, it tells you whether the 200 OK was retransmitted, whether an ACK ever matched it, and where the ACK most likely went.

Where the 32 comes from

The 200 OK is retransmitted 11 times, every ACK goes to a private address, BYE at 32 s

An INVITE is a three-way handshake: INVITE, 200 OK, ACK. The 200 OK is the odd one out. RFC 3261 section 13.3.1.4 says the INVITE server transaction is destroyed as soon as it passes the 2xx to the transport, so the UAS core itself has to keep re-sending it "until the ACK arrives". The interval "starts at T1 seconds and doubles for each retransmission until it reaches T2 seconds". It does this even over TCP, because "2xx is retransmitted end-to-end, there may be hops between UAS and UAC that are UDP." (RFC 6026 later rewrote that paragraph, but kept the T1/T2 retransmission rule.)

Then comes the line that explains your CDRs:

If the server retransmits the 2xx response for 64*T1 seconds without receiving an ACK, the dialog is confirmed, but the session SHOULD be terminated. This is accomplished with a BYE, as described in Section 15.

The defaults in RFC 3261 Table 4 are T1 = 500 ms and T2 = 4 s. So 64 x 0.5 s = 32 seconds, and the 200 OK goes out at 0, 0.5, 1.5, 3.5, 7.5, 11.5, 15.5, 19.5, 23.5, 27.5 and 31.5 s. That's 11 copies, then a BYE. The tool computes the same schedule:

export function expectedSchedule(t1 = RFC_T1, t2 = RFC_T2): number[] {
  const out = [0];
  for (let t = 0, iv = t1; (t += iv) < 64 * t1; iv = Math.min(iv * 2, t2)) out.push(t);
  return out;
}

If your stack uses a different T1, the drop moves with it (T1 = 1 s gives 64 s). The tool infers T1 from the first retransmission gap, or you can pass --t1.

Why the ACK doesn't follow the INVITE

The ACK for a 2xx is not part of the INVITE transaction. RFC 3261 section 13.2.2.4: its headers are "constructed in the same way as for any request sent within a dialog". That means it isn't sent back along the Via path. It's sent to the dialog's remote target, using the dialog's route set.

Both come from the 200 OK (section 12.1.2):

  • Route set = the Record-Route values from the response, in reverse. No Record-Route means an empty route set.
  • Remote target = the URI in the response's Contact.

And section 12.2.1.1: "If the route set is empty, the UAC MUST place the remote target URI into the Request-URI."

So with no Record-Route, the ACK goes wherever the callee's Contact points, no matter which proxy the INVITE came through. That's where most 32-second drops start.

The usual suspects

1. A private or CGNAT Contact, and nobody Record-Routes. The callee sits behind a NAT and writes its LAN address into the 200 OK: Contact: <sip:bob@192.168.1.20:5060>. The 200 OK reaches the caller fine, because responses follow the Via path back. The ACK goes to 192.168.1.20, which means nothing from outside that network. The same thing happens with mobile clients in carrier-grade NAT space, 100.64.0.0/10 (RFC 6598). The tool's check is short:

if (unroutable(host) && !rr.length) {
  f.push({ severity: sev('error'), code: 'CONTACT_UNROUTABLE_NO_RR', message: `200 OK Contact <${contact.raw}> is ${scopeLabel(host)} and there is no Record-Route. ...` });
}

2. A proxy that forwards the INVITE but doesn't Record-Route. Section 16.6 step 4: a proxy that wants to stay on the path of later requests "MUST insert a Record-Route header field value". If it doesn't, the ACK and the BYE go straight from caller to callee and skip that proxy, along with any NAT handling it was doing. You can spot this in the trace: the INVITE has two Via headers, and the 200 OK has no Record-Route.

3. Record-Route without ;lr. The same section says the URI a proxy puts in Record-Route "MUST contain an lr parameter". Without it, the caller treats that proxy as an old RFC 2543 strict router. Per section 12.2.1.1, the ACK's Request-URI becomes the proxy's URI and the real target moves to the end of the Route header. A compliant proxy rewrites that on receipt (section 16.4). One that doesn't can lose your ACK.

4. A transport mismatch. The dialog runs over UDP, but the callee's Contact says ;transport=tcp. RFC 3263 section 4.1: if the URI has a transport parameter, "that transport protocol SHOULD be used". So the caller opens TCP for the ACK, and if nothing accepts TCP on that address, no ACK arrives.

5. The ACK arrives, but doesn't match. The callee only stops retransmitting when it gets an ACK for that dialog. Section 13.2.2.4 requires the ACK's CSeq number to be "the same as the INVITE being acknowledged". Section 12.2.1.1 requires the dialog's Call-ID and the remote tag in To. A classic bug: the first INVITE gets a 401, the retry goes out as CSeq 2, and the ACK reuses CSeq 1. The matching rule in the tool:

const matches = (a: SipMessage) => cseqOf(a)?.num === cseq && cseqOf(a)?.method === 'ACK'
  && tagOf(header(a, 'to')) === toTag && tagOf(header(a, 'from')) === fromTag;

6. Everything is right, and the ACK still disappears. Public Contact, correct tags, an ACK leaves after every 200 OK, and the 200 OK keeps coming. Then the problem is in the path: a NAT binding, a SIP ALG rewriting or dropping the packet, or a firewall rule.

What the tool prints

Here is the real output for the NAT case. The 200 OK times match the RFC schedule exactly, the BYE lands at 32 s, and the caller's ACKs all go to the private address:

sip-ack-timeout-doctor output for the private-Contact trace

It's 451 lines of TypeScript with zero runtime dependencies. Node 22.18+ runs the .ts files directly. It reads ngrep/sngrep-style text: messages separated by ---, each optionally preceded by a capture line like U 2026/11/29 10:00:03.000000 192.0.2.50:5060 -> 198.51.100.10:5060. It groups messages by Call-ID. If the capture point is a proxy that sees each 200 OK twice (in and out), it counts only the copies on the UAS side.

Eight synthetic traces

The repo ships eight traces generated by a script in the repo. None is a capture from a real network. They use RFC 5737 documentation addresses for the public side, and RFC 1918 and RFC 6598 addresses for the "inside". On Node v24.22.1, seven of the eight calls time out, each for a different reason:

| Trace | Likely cause reported | |---|---| | 01 proxy Record-Routes with ;lr, ACK follows the route set | none, looks correct | | 02 callee behind NAT, Contact 192.168.1.20, no Record-Route | CONTACT_UNROUTABLE_NO_RR | | 03 seen on a proxy that doesn't Record-Route, Contact in 100.64.0.0/10 | CONTACT_UNROUTABLE_NO_RR + PROXY_NOT_RECORD_ROUTING | | 04 Record-Route: <sip:203.0.113.5> without ;lr | RECORD_ROUTE_NO_LR | | 05 UDP dialog, Contact ;transport=tcp | TRANSPORT_MISMATCH | | 06 ACK reuses CSeq 1 after a 401, no To tag | ACK_MISMATCH | | 07 everything correct, ACK still lost | ACK_LOST_IN_PATH | | 08 ACK carries the other leg's Call-ID | ACK_CALL_ID_MISMATCH |

The test suite has 18 node:test tests. They cover the exact RFC schedule (11 sends, the last at 31.5 s), proxy captures that see each 200 OK twice, a late ACK that still saves the call, T1 inferred from a 1-second first gap, and compact headers. All 18 pass locally and in GitHub Actions CI on Node 22 and 24. The CLI exits with code 2 when it finds an error, so you can point it at recorded traces in CI.

What it can't see

A capture shows one point in the network. "No ACK seen" on a proxy only means "no ACK through this proxy". The tool doesn't resolve DNS the way RFC 3263 does, and it doesn't see failed TCP connects or what your SBC rewrote. Use it to decide where to capture next. Usually that's at the UAS, and on both sides of the NAT.

The takeaway

When calls drop at a round, repeatable number of seconds, stop looking at media and look at the ACK. Open the 200 OK and ask three questions. Where does its Contact point? Is there a Record-Route, and does it have ;lr? Did an ACK with the same Call-ID, CSeq number and To tag ever reach the callee? One of those answers is usually the bug.


Code: github.com/AhmedElbashier/sip-ack-timeout-doctor has the CLI, eight synthetic traces, 18 tests and the raw run output. Run npm test, then node src/cli.ts traces/*.sip.

I'm Ahmed, a full-stack and integrations engineer (.NET, Next.js, VoIP/WebRTC/SIP). More of my work is on GitHub and my portfolio.


Sumber artikel open-source oleh Ahmed Elbashier di DEV Community — Baca artikel asli. Topik: #voip #webrtc #networking #typescript

Sukai & bagikan artikel ini

Komentar