twilio-32009Twiliohigh

SDP Negotiation Failed

The SDP offer/answer exchange failed during call setup, usually due to codec mismatches or network issues.

What this error means

Error 32009 occurs when Twilio's Session Description Protocol (SDP) negotiation fails during the initial call setup phase. SDP is the standardized format used to describe media capabilities between two endpoints (codecs, bitrates, network addresses, etc.). When the offer/answer exchange breaks down, the two parties cannot agree on how to establish the media stream, preventing the call from connecting. This is a critical phase that must succeed before any audio or video can flow between participants.

Root causes

high

Codec mismatch between caller and callee endpoints

Common

high

Network connectivity issues preventing SDP message delivery

Common

high

Firewall or NAT traversal problems blocking media negotiation

Occasional

critical

Invalid or malformed SDP in offer/answer

Occasional

high

Missing or incompatible STUN/TURN server configuration

Occasional

medium

Timeout during SDP exchange (slow network)

Occasional

medium

Browser or WebRTC implementation incompatibility

Rare

medium

Concurrent call limit or resource exhaustion on Twilio infrastructure

Rare

How to fix it

  1. 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. 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. 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. 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. 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. 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. 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. 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