Fix 27s call ringing delay: TURN credential mismatch and STUN DNS TTL=0

Two bugs caused ICE candidate gathering to fail and timeout (~27 seconds)
before falling back to direct media on every call:

1. TURN credential mismatch — when TURN_PASSWORD was empty in .env,
   coturn defaulted to "changeme" but the entrypoint auto-generated a
   different random password for Asterisk. Every TURN auth attempt failed
   ("check_stun_auth: user easyasterisk credentials are incorrect").

2. STUN DNS TTL=0 — using the FQDN as stunaddr caused DNS resolution
   that returned TTL=0, making Asterisk cancel recurring STUN resolution
   entirely. Since coturn runs on the same host (network_mode: host),
   rtp.conf now uses 127.0.0.1 which needs no DNS at all.

Also documents the Android Call Integration audio issue (ConnectionService
routes audio through the native telephony path, breaking VoIP RTP).

https://claude.ai/code/session_01KWVtEt9MmZdywcu7WmgchX
This commit is contained in:
Claude
2026-02-24 22:07:33 +00:00
parent cbccaa4218
commit de46202ab4
4 changed files with 36 additions and 16 deletions
+17 -13
View File
@@ -54,17 +54,15 @@ else
log_warn "Could not detect public IP. Set PUBLIC_IP in .env"
fi
# ── 3. Generate TURN password if not provided ─────────────────
# ── 3. TURN credentials ─────────────────────────────────────────
# The password MUST match what coturn was started with. In Docker, both
# read from the same env-var / .env file, so we use the value as-is.
# Auto-generating a different password here would create a mismatch
# (coturn is already running with ITS copy of the env-var).
TURN_USERNAME="${TURN_USERNAME:-easyasterisk}"
if [[ -z "${TURN_PASSWORD:-}" ]] || [[ "${TURN_PASSWORD}" == "changeme" ]]; then
# Check if we already generated one previously
if [[ -f "$CONFIG_FILE" ]] && grep -q "^TURN_PASSWORD=" "$CONFIG_FILE"; then
TURN_PASSWORD=$(grep "^TURN_PASSWORD=" "$CONFIG_FILE" | cut -d'"' -f2)
fi
if [[ -z "${TURN_PASSWORD:-}" ]] || [[ "${TURN_PASSWORD}" == "changeme" ]]; then
TURN_PASSWORD=$(gen_password)
log_info "Generated TURN password (saved to config)"
fi
TURN_PASSWORD="${TURN_PASSWORD:-changeme}"
if [[ "${TURN_PASSWORD}" == "changeme" ]]; then
log_warn "TURN password is the default 'changeme' — set TURN_PASSWORD in .env for better security"
fi
# ── 4. Detect local network ──────────────────────────────────
@@ -282,15 +280,21 @@ EOF
fi
# ── rtp.conf (always regenerated - includes TURN credentials) ──
log_info "Configuring RTP with ICE + STUN + TURN..."
# Use 127.0.0.1 for stunaddr/turnaddr because coturn runs on the same host
# (network_mode: host). Using the FQDN would cause DNS resolution, and if the
# DNS TTL is 0 Asterisk cancels recurring resolution — breaking ICE entirely
# and adding a ~27-second timeout delay to every call.
turn_port="${turn_server##*:}"
local_turn="127.0.0.1:${turn_port:-3478}"
log_info "Configuring RTP with ICE + STUN + TURN (local: ${local_turn})..."
cat > /etc/asterisk/rtp.conf << EOF
[general]
rtpstart=${RTP_START:-10000}
rtpend=${RTP_END:-20000}
strictrtp=yes
icesupport=yes
stunaddr=${turn_server}
turnaddr=${turn_server}
stunaddr=${local_turn}
turnaddr=${local_turn}
turnusername=${TURN_USERNAME}
turnpassword=${TURN_PASSWORD}
EOF