Google is committed to advancing racial equity for Black communities. See how.

502 Bad Gateway - TooBigLine

You're viewing Apigee Edge documentation.
View Apigee X documentation.

Symptom

The client application gets an HTTP status code of 502 Bad Gateway with error code protocol.http.TooBigLine as a response for API calls.

Error message

Client application gets the following response code:

HTTP/1.1 502 Bad Gateway

In addition, you may observe the following error message:

{
   "fault":{
      "faultstring":"response line size exceeding 2,048",
      "detail":{
         "errorcode":"protocol.http.TooBigLine"
      }
   }
}

Possible causes

This error occurs if the Response-Line size sent by the target/backend server to Apigee Edge as part of the HTTP response is greater than the maximum allowed limit in Apigee Edge.

Before we look at the possible causes for this error, let’s understand what the Response-Line means and how to check its size.

Understanding Response-Line

A typical HTTP response consists of three parts:

  1. Status-Line (Referred to as Response-Line in Apigee)
  2. ( Set of HTTP headers )
  3. [ Body ]

The Response-Line consists of three parts: protocol version followed by a numeric status code and its associated textual phrase as shown below:

Response-Line   = <HTTP-Version> <Status-Code> <Reason-Phrase>

When an HTTP response is sent by the target/backend server application, the first line that is sent represents the Response-Line as described above. This is followed by the headers and response body/payload.The following sample screenshot shows a typical curl request, the Request part and the Response part (along with the Response-Line).

Understanding Response-Line size

  1. In the sample discussed above, the start line (first line) in the response also referred as Response-Line is as follows:

    HTTP/1.1 200 OK
    

    This Response-Line has a size as ~15 bytes since it contains 15 ASCII characters. Since this is within the allowed limit in Apigee Edge, the response is sent back to the client without any errors by Apigee Edge.

  2. Similarly if you look at the faultstring in the Error message shown above, it contains "response line size exceeding 2,048". This indicates that the Response-Line in the HTTP response sent by the target/backend server exceeded 2,048 bytes.

Understanding large Response-Line

As per the definition of Status-Line (referred to as Response-Line here) and typical HTTP requests and response, the size would be much smaller than the defined default limit of 2 K in Apigee Edge, so we may not hit the limit. However, here are some possible scenarios where you may exceed this limit:

  1. The target/backend server is not an HTTP system. It could be responding with a non-HTTP response.
  2. The target/backend server has issues and sends a long Response-Line as part of the HTTP response.

Read more about this in Getting error protocol.http.TooBigLine, "response line size exceeding 2,048.

Here are the possible causes for the error:

Cause Description Troubleshooting instructions applicable for
Response-Line size is greater than allowed limit The size of the Response-Line sent by the target/backend server as part of the HTTP response to Apigee Edge is greater than the allowed limit in Apigee Edge Edge Public and Private Cloud users

Common diagnosis steps

Use one of the following tools/techniques to diagnose this error:

API Monitoring

To diagnose the error using API Monitoring:

  1. Sign in to Apigee Edge UI as a user with an appropriate role.
  2. Switch to the organization in which you want to investigate the issue.

  3. Navigate to the Analyze > API Monitoring > Investigate page.
  4. Select the specific timeframe in which you observed the errors.
  5. You may select the Proxy filter to narrow down the fault code.
  6. Plot Fault Code against Time.
  7. Select a cell which has the fault code protocol.http.TooBigLine as shown below:

    ( view larger image)

  8. You will see the information about the fault code protocol.http.TooBigLine as shown below:

    ( view larger image)

  9. Click View logs and expand the row for the failed request.

  10. From the Logs window, note the following details:
    • Status Code: 502
    • Fault Source: target
    • Fault Code: protocol.http.TooBigLine.
  11. If the Fault Source has the value target and the Fault Code has the value protocol.http.TooBigLine, then that indicates that the HTTP response from the target/ backend server has a Response-Line size greater than the maximum allowed limit in Apigee Edge.

Trace tool

  1. Enable the trace session and either:
    1. Wait for the 502 Bad Gateway error to occur. or
    2. If you can reproduce the issue, make the API call and reproduce 502 Bad Gateway error.
  2. Select one of the failing requests and examine the trace.
  3. Navigate through different phases of the trace and locate where the failure occurred.
  4. You will typically find the error in the flowinfo Error just after the Request sent to target server phase as shown below:

    Note the values of the error from the trace:

    • error: response line exceeding 2,048
    • error.class: com.apigee.errors.http.server.BadGateway

    This indicates that Apigee Edge (Message Processor component) throws the error as soon as it receives the response from the backend server due to a Response-Line size exceeding the allowed limit.

  5. You would see the error message sent to the client in the Response Sent to Client phase as shown below:

    ( view larger image)

  6. Note the values of the error from the trace:
    • Error: 502 Bad Gateway.
    • Error Content: {"fault":{"faultstring":"response line exceeding 2,048","detail":{"errorcode":"protocol.http.TooBigLine"}}}
  7. You may also navigate to the AX (Analytics Data Recorded) phase in the trace and click on it to see the error details.

    ( view larger image)

    Note the value of the following:

    Request headers Value
    X-Apigee-fault-code protocol.http.TooBigLine
    X-Apigee-fault-source target
    Error Content : Body {"fault":{"faultstring":"response line size exceeding 2,048","detail":{"errorcode":"protocol.http.TooBigLine"}}}

Nginx

To diagnose the error using Nginx access logs:

  1. If you are a Private Cloud user, then you can use Nginx access logs to determine the key information about HTTP 502 errors.
  2. Check the Nginx access logs:

    /opt/apigee/var/log/edge-router/nginx/ORG~ENV.PORT#_access_log

    Where: ORG, ENV, and PORT# are replaced with actual values.

  3. Search to see if there are any 502 errors during a specific duration (if the problem happened in the past) or if there are any requests still failing with 502.
  4. If you do find any 502 errors with the X-Apigee-fault-code matching the value of protocol.http.TooBigLine, then determine the value of the X-Apigee-fault-source.

    The above sample entry from the Nginx acess log has the following values for X- Apigee-fault-code and X-Apigee-fault-source:

    Response Headers Value
    X-Apigee-fault-code protocol.http.TooBigLine
    X-Apigee-fault-source target

Cause: Response-Line size is greater than allowed limit

Diagnosis

  1. Determine the Fault Code and Fault Source for the error observed using API Monitoring, Trace tool or Nginx access logs as explained in Common diagnosis steps.
  2. If the Fault Source has the value target, then this indicates that the Response-Line size sent by the target/backend server application to Apigee is greater than the allowed limit in Apigee Edge.
  3. You can validate that the Response-Line size has exceeded the 2 KB allowed limit using one of the following methods:

    Error message

    To validate using the error message:

    If you have access to the complete error message received from Apigee Edge, then refer to the faultstring.

    Sample error message:

    "faultstring":"response line size exceeding 2,048"
    

    The above faultstring indicates that the Response-Line size exceeded the allowed limit of 2 KB.

    Actual request

    To validate using the actual request:

    If you have access to the actual request made to the target/backend server application, then perform the following steps:

    1. Verify the size of the Response-Line
    2. If you find that the size of the URI is more than the allowed limit in Apigee Edge, then that is the cause of the issue.

      Sample response from the target/backend server:

      curl -v http://HOSTALIAS/test
      
      *   Trying 3.2.1.4...
      * TCP_NODELAY set
      * Connected to <hostalias> (3.2.1.4) port 80 (#0)
      > GET /test HTTP/1.1
      > Host: HOSTALIAS
      > User-Agent: curl/7.64.1
      > Accept: */*
      >
      < HTTP/1.1 200 1111…<trimmed>...11111111
      < Date: Mon, 26 Jul 2021 07:07:18 GMT
      < Content-Type: application/json
      < Content-Length: 269
      < Connection: keep-alive
      < Server: gunicorn/19.9.0
      < Access-Control-Allow-Origin: *
      < Access-Control-Allow-Credentials: true
      <
      {
      <Response Body>
      }
      * Connection #0 to host <hostalias> left intact
      * Closing connection 0
      

      In the above case, the Response-Line HTTP/1.1 200 1111…<trimmed>...11111111 is larger than 2 KB, that is, it contains more than 2 K ASCII characters.

      If you are using some other client, you can review the client logs and try to find out the size of the Response-Line being sent to Apigee Edge.

    Message Processor logs

    To validate using Message Processor logs:

    If you are a Private Cloud user, then you can use Message Processor logs to validate if the Response-Line size has exceeded the allowed limit in Apigee Edge.

    1. Determine the message ID of the failing request using API Monitoring, Trace tool, or Nginx access logs as explained in Common diagnosis steps.
    2. Search for the message ID in the Message Processor log:

      /opt/apigee/var/log/edge-message-processor/logs/system.log

    3. You will find lines from system.log similar to the following:

      2021-07-26 06:45:41,451 org:myorg env:prod api:testtoobigline rev:1 messageid:r-5110240-1
      NIOThread@1 ERROR HTTP.CLIENT - HTTPClient$Context$3.onException() :
      ClientChannel[Connected: Remote:3.2.1.2:80 Local:192.168.205.251:44398]@20592
      useCount=1 bytesRead=0 bytesWritten=201 age=144ms  lastIO=0ms  isOpen=true.onExceptionRead
      exception: {}
      com.apigee.errors.http.server.BadGateway: response line size exceeding 2,048
      at <snipped>
      
      2021-07-26 06:45:41,451 org:myorg env:prod api:testtoobigline rev:1
      messageid:r-5110240-1  NIOThread@1 ERROR ADAPTORS.HTTP.FLOW -
      AbstractResponseListener.onException() : AbstractResponseListener.onError
      (HTTPResponse@6a5d6c33, response line size exceeding 2,048)
      

      The text message = response line size exceeding 2,048 in the above error message indicates that the Response-Line size is more than 2 KB. Therefore, Apigee Edge throws the exception and returns a 502 status code with fault code protocol.http.TooBigline to client applications.

Resolution

Fix size

Option #1 [Recommended]: Fix the target/backend server application not to send Response-Lines of size greater than the allowed limit

  1. Analyze the reason for the specific client to send a Response-Line of size more than allowed limit as defined in Limits.
  2. If it is not desirable, modify your target/backend server application so that it sends a Response-Line of size less than the allowed limit.
  3. If it is desirable and you want to send a Response-Line of size more than the allowed limit, go to the next options.

CwC

Option #2: Use CwC property to increase the Response-Line limit

Apigee provides a CwC property which allows it to increase the Response-Line size limit. For details, see Set the Response-Line limit on the Message Processor.

Limits

Apigee expects the client application and backend server do not send Request/Response-Lines whose sizes are greater than the allowed limit as documented for Request/Response Line Limit in Apigee Edge Limits.

  1. If you are a Public Cloud user, then the maximum limit for Request and Response Line size is as documented for Request/Response-Line size in Apigee Edge Limits.
  2. If you are a Private Cloud user, then you may have modified the default maximum limit for Request and Response-Line size (even though it is not a recommended practice). You can determine the maximum Response-Line size limit by following instructions in How to check the current limit.

How to check the current limit?

This section explains how to verify that the property HTTPResponse.line.limit has been updated with a new value on the Message Processors.

  1. On the Message Processor machine, search for the property HTTPResponse.line.limit in the /opt/apigee/edge-message-processor/conf directory and check to see what value has been set as shown below:
    grep -ri "HTTPResponse.line.limit" /opt/apigee/edge-message-processor/conf
    
  2. The sample result from the above command is as follows:
    /opt/apigee/edge-message-processor/conf/http.properties:HTTPResponse.line.limit=2k
    
  3. In the example output above, notice that the property HTTPResponse.line.limit has been set with the value 2k in http.properties.

    This indicates that the limit for the Response-Line size configured in Apigee for Private Cloud is 2 KB.

If you still need any assistance from Apigee Support, go to Must gather diagnostic information.

Must gather diagnostic information

Gather the following diagnostic information, and then contact Apigee Support:

If you are a Public Cloud user, provide the following information:

  • Organization name
  • Environment name
  • API Proxy name
  • Complete curl command used to reproduce the 502 error
  • Trace file for the API requests

If you are a Private Cloud user, provide the following information:

  • Complete error message observed for the failing requests
  • Organization name
  • Environment name
  • API Proxy bundle
  • Trace file for the failing API requests
  • Complete curl command used to reproduce the 502 error
  • Nginx access logs /opt/apigee/var/log/edge-router/nginx/ORG~ENV.PORT#_access_log

    Where: ORG, ENV and PORT# are replaced with actual values.

  • Message Processor system logs /opt/apigee/var/log/edge-message-processor/logs/system.log