twilio-32009TwiliohighSDP Negotiation Failed
The SDP offer/answer exchange failed during call setup, usually due to codec mismatches or network issues.
What this error means
Root causes
Codec mismatch between caller and callee endpoints
Common
Network connectivity issues preventing SDP message delivery
Common
Firewall or NAT traversal problems blocking media negotiation
Occasional
Invalid or malformed SDP in offer/answer
Occasional
Missing or incompatible STUN/TURN server configuration
Occasional
Timeout during SDP exchange (slow network)
Occasional
Browser or WebRTC implementation incompatibility
Rare
Concurrent call limit or resource exhaustion on Twilio infrastructure
Rare
How to fix it
- 1
Verify codec compatibility
Check that both endpoints support at least one common codec. Review your Twilio application configuration and client-side codec settings. Ensure you're not forcing unsupported codecs. Common codecs include OPUS, PCMU, and PCMA for audio. Log the SDP offer/answer to identify which codecs are being negotiated.
- 2
Test network connectivity
Verify both endpoints have stable internet connectivity. Run a network diagnostic test using tools like speedtest.net or Twilio's network diagnostic APIs. Check for packet loss, latency, and jitter. Test from both the caller and callee networks independently to isolate connectivity issues.
- 3
Configure STUN/TURN servers
Ensure your Twilio SDK configuration includes proper STUN and TURN servers for NAT traversal. Twilio provides default servers, but verify they're enabled in your client configuration. If behind a restrictive firewall, explicitly configure TURN servers with valid credentials.
{ "iceServers": [ { "urls": "stun:stun.l.google.com:19302" }, { "urls": "turn:your-turn-server.com", "username": "user", "credential": "pass" } ] } - 4
Check firewall and port rules
Verify that your firewall allows UDP ports 5000-65535 (or your configured media port range) for RTP/RTCP traffic. Check both inbound and outbound rules. If behind a corporate firewall, work with your IT team to whitelist Twilio's media servers and STUN/TURN endpoints.
- 5
Enable SDP logging and debugging
Implement detailed logging of SDP offer/answer exchanges in your application. Log the full SDP strings, timestamps, and any error messages from the WebRTC or Twilio SDK. Use browser DevTools (Chrome/Firefox) to capture WebRTC stats and ICE candidate gathering.
connection.on('offer', (offer) => { console.log('SDP Offer received:', offer.sdp); console.log('Offer timestamp:', new Date().toISOString()); }); connection.on('answer', (answer) => { console.log('SDP Answer sent:', answer.sdp); }); - 6
Validate SDP format
If generating custom SDP, validate it against RFC 4566 standards. Use an SDP parser/validator to ensure all required fields are present and properly formatted. Check for missing connection information (c=), media lines (m=), and attribute lines (a=). Invalid SDP will fail negotiation.
- 7
Test with Twilio diagnostics
Use Twilio's built-in network and media diagnostics tools. Enable verbose logging in the Twilio SDK. Review Twilio console logs for the specific call SID to see detailed error information from Twilio's perspective. Contact Twilio support with the call SID for deeper inspection.
- 8
Implement retry logic with exponential backoff
Add resilient retry logic for call setup failures. Implement exponential backoff when retrying failed calls. After 3-5 failed attempts, alert the user or escalate to support. This buys time for network conditions to stabilize.
async function initiateCallWithRetry(maxRetries = 3) { for (let i = 0; i < maxRetries; i++) { try { await twilioClient.initiateCall(targetNumber); return; } catch (error) { if (error.code === 32009) { const delay = Math.pow(2, i) * 1000; await new Promise(r => setTimeout(r, delay)); } else { throw error; } } } }
Prevention
Prevent SDP negotiation failures by establishing robust codec negotiation strategies (support multiple codecs), implementing comprehensive network monitoring and health checks before initiating calls, properly configuring STUN/TURN servers, regularly testing call setup from diverse network environments (home, office, mobile), and maintaining detailed call setup telemetry to detect patterns early. Implement client-side validation of SDP before sending it to Twilio, and maintain clear separation between media negotiation logic and application business logic to simplify debugging.
Debugging this right now?
Sherlock diagnoses twilio-32009 automatically. Just ask in Slack and get an instant root-cause analysis.
Add to Slack — Free