502 閘道錯誤 - DecompressionFailureAtResponse

您正在查看 Apigee Edge 說明文件。
查看 Apigee X 說明文件
資訊

問題

用戶端應用程式會取得 502 Bad Gateway 的 HTTP 狀態碼,以及錯誤代碼 messaging.adaptors.http.flow.DecompressionFailureAtResponse 來回應 API 呼叫。

錯誤訊息

用戶端應用程式會取得以下回應代碼:

HTTP/1.1 502 Bad Gateway

此外,您可能會看見類似以下的錯誤訊息:

{
   "fault":{
      "faultstring":"Decompression failure at response",
      "detail":{
         "errorcode":"messaging.adaptors.http.flow.DecompressionFailureAtResponse"
      }
   }
}

可能原因

只有在發生以下情況時才會發生這個錯誤:

  • HTTP 回應 (來自後端/目標伺服器) 標頭 Content-Encoding 中指定的編碼有效,且 Apigee Edge 支援
  • 但是

  • HTTP 回應中,後端/目標伺服器傳送的酬載格式與 Content-Encoding 標頭中指定的編碼格式不符。

這是因為酬載的格式與 Content-Encoding 標頭中指定的編碼格式不同,因此 Apigee Edge 無法使用指定的編碼解碼酬載。

以下列舉幾個支援的 Content-Encoding 值,以及 Apigee Edge 預期酬載表示法在這些情況下的情況:

情境 Content-Encoding 酬載表示法
單一編碼 gzip

Unix gzip 格式。

請參閱 RFC1952 GZIP 格式

單一編碼 誹謗

這種格式使用 zlib 結構搭配延遲壓縮演算法。

詳情請參閱 RFC1950 RFC1951.

多個編碼

多個編碼

舉例來說,如果編碼作業兩次,以下是可能的結果:

  • gzip、deflate
  • gzip、gzip
  • deflate, gzip
  • 延遲, 降低
依照標頭中顯示的指定順序,套用至酬載的多種編碼。

此錯誤的可能原因如下:

原因 說明 適用的疑難排解指示
回應酬載格式與 Content-Encoding 不符 後端/目標伺服器傳送的回應酬載格式並未編碼,或是與 Content-Encoding 標頭中指定的編碼不符。 Edge Public and Private Cloud 使用者

常見診斷步驟

請使用下列其中一種工具/技巧診斷這項錯誤:

API Monitoring

如何使用 API Monitoring 診斷錯誤:

  1. 適當角色的使用者 登入 Apigee Edge UI
  2. 切換至您想要調查問題的機構。

  3. 前往「分析」>「API 監控」>「調查」頁面。
  4. 請選取你發現錯誤的特定時間範圍。
  5. 確認「Proxy」篩選器已設為「全部」
  6. 將「Fault Code」與「Time」進行比較。
  7. 選取含有錯誤代碼 messaging.adaptors.http.flow.DecompressionFailureAtResponse 的儲存格,如下所示:

    ( 查看較大圖片)。

  8. 錯誤代碼 messaging.adaptors.http.flow.DecompressionFailureAtResponse 的相關資訊如下所示:

    ( 查看較大圖片)。

  9. 按一下「查看記錄」,然後展開出現 502 錯誤失敗的資料列。

    ( 查看較大圖片)。

  10. 在「記錄檔」視窗中記下下列詳細資料:
    • 狀態碼: 502
    • Fault 資料來源: target
    • 錯誤代碼: messaging.adaptors.http.flow.DecompressionFailureAtResponse
  11. 如果「Fault Source」的值為 target,表示回應酬載格式與後端伺服器回應標頭 Content-Encoding 中指定的 支援編碼不符。

追蹤工具

如何使用追蹤工具診斷錯誤:

  1. 啟用追蹤工作階段,然後採取下列其中一種做法:
    1. 等待發生 502 Bad Gateway 錯誤,或
    2. 如果可以重現問題,請發出 API 呼叫並重現 502 Bad Gateway
  2. 確保已啟用「Show all FlowInfos」

  3. 請選取其中一個失敗的回應,並檢查追蹤記錄。
  4. 瀏覽追蹤記錄的不同階段,找出發生錯誤的位置。
  5. 您通常會在「Response Received from 目標伺服器」階段後的流程中看到錯誤,如下所示:

    ( 查看較大圖片)。

  6. 記下追蹤記錄中的屬性值:

    • 內容編碼: gzip
    • 回應內容內文: {"fault":{"faultstring":"Decompression failure at response","detail":{"errorcode":"messaging.adaptors.http.flow.DecompressionFailureAtResponse"}}}
  7. 前往「Response Received from 目標伺服器」階段之後的錯誤階段:

    ( 查看較大圖片)。

    請注意屬性:

    • 錯誤: Decompression failure at response
    • error.class: com.apigee.errors.http.server.BadGateway
    • error.cause: Not in GZIP format

      error.cause 指出回應酬載並非採用 GZIP 格式。這表示 Apigee Edge 預期回應酬載是採用 Content-Encoding 標頭指定的 GZIP 格式 (如上一個步驟所示)。因此,Apigee Edge 無法使用 gzip 解壓縮酬載,並傳回錯誤 Decompression failure at response

    請注意,在這個情況下,目標/後端伺服器的回應是 200;不過,由於 Apigee Edge 傳回錯誤,因此用戶端應用程式會收到 502 回應。

  8. 前往追蹤記錄中的「Response Sent to Client」階段,然後按一下該階段。

    ( 查看較大圖片)。

    記下追蹤記錄中的下列詳細資料:

    • 狀態碼: 502 Bad Gateway
    • 錯誤內容: {"fault":{"faultstring":"Decompression failure at response","detail":{"errorcode":"messaging.adaptors.http.flow.DecompressionFailureAtResponse"}}}
  9. 前往追蹤記錄中的「AX」(Analytics (分析) 資料記錄) 階段,然後按一下該階段。

  10. 向下捲動至「階段詳細資料」、「錯誤標頭」區段,確定 X-Apigee-fault-codeX-Apigee-fault-source 的值,如下所示:

    ( 查看較大圖片)。

  11. 您會看到 X-Apigee-fault-codeX-Apigee-fault-source 的值為 messaging.adaptors.http.flow.DecompressionFailureAtResponsetarget,表示回應酬載格式與 Content-Encoding 標頭中指定的編碼不符。
    回應標頭
    X-Apigee-fault-code messaging.adaptors.http.flow.DecompressionFailureAtResponse
    X-Apigee-fault-source target

NGINX

如何使用 NGINX 存取記錄檔診斷錯誤:

  1. 如果您是 Private Cloud 使用者,即可使用 NGINX 存取記錄檔來判斷 HTTP 502 錯誤的相關重要資訊。
  2. 查看 NGINX 存取記錄檔:

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

    其中:ORGENVPORT# 替換為實際值。

  3. 搜尋特定時間範圍內是否有任何 502 錯誤 (如果問題過去發生),或是否有任何回應仍為 502 失敗。
  4. 如果在 X-Apigee-fault-code 中發現符合 messaging.adaptors.http.flow.DecompressionFailureAtResponse 值的任何 502 錯誤,請找出 X-Apigee-fault-source 的值。

    NGINX 存取記錄中的 502 錯誤示例:

    以上 NGINX 存取記錄中的範例項目,有下列「X-Apigee-fault-code」X-Apigee-fault-code 和「X-Apigee-fault-source」X-Apigee-fault-code 的值:

    回應標頭
    X-Apigee-fault-code messaging.adaptors.http.flow.DecompressionFailureAtResponse
    X-Apigee-fault-source target

原因:回應酬載格式與 Content-編碼不符

根據預設,如果回應標頭 Content-Encoding 包含有效且 支援的編碼,Apigee Edge 一律會解壓縮酬載。因此,回應酬載的格式應符合回應標頭 Content-Encoding 中指定的編碼。如果出現不相符的情形,就會收到這則錯誤訊息。

診斷

  1. 使用 API 監控、追蹤工具或 NGINX 存取記錄檔,按照常見診斷步驟的說明,找出錯誤的「Fault Code」和「Fault Source」
  2. 如果「Fault Code」messaging.adaptors.http.flow.DecompressionFailureAtResponse,且「Fault Source」的值為 target,表示後端/目標伺服器傳送的回應酬載格式與回應標頭 Content-Encoding 中指定的 支援的編碼不符。
  3. 您可以使用下列其中一個方法,判斷 HTTP 回應中不相符的項目:

    錯誤訊息

    如何使用錯誤訊息進行驗證:

    1. 如果您可以存取從 Apigee Edge 收到的完整錯誤訊息,請參閱 faultstring

      錯誤訊息示例:

      "faultstring":"Decompression failure at response"
      
    2. 在上述錯誤訊息中,系統會顯示 "Decompression failure at response",這表示無法以 Content-Encoding 標頭中指定的編碼方式將回應解壓縮。

    追蹤記錄

    如何使用 Trace 進行驗證:

    1. 按照常見診斷步驟的說明,使用 Trace 決定 Content-Typeerror.cause
    2. 範例追蹤記錄中的值如下:

      • 內容編碼: gzip
      • error.cause: Not in GZIP format

      回應標頭 Content-Encoding 中的值是 gzip,但回應酬載並非採用 GZIP 格式 (如 error.cause 所示)。因此,Apigee Edge 會以 502 Bad Gateway 和錯誤代碼 messaging.adaptors.http.flow.DecompressionFailureAtResponse 回應。

    實際要求

    如何使用實際要求進行驗證:

    如果您可以存取對目標/後端伺服器應用程式傳送的實際要求,請執行下列步驟:

    1. 如果您是公開雲端/私有雲使用者,請從後端伺服器本身,或是您允許向後端伺服器發出要求的其他機器,直接向後端伺服器發出要求。
    2. 如果您是 Private Cloud 使用者,也可以從其中一個訊息處理器向後端伺服器發出要求。
    3. 檢查後端伺服器傳送的回應,並判斷回應標頭 Content-Encoding. 中傳遞的值
    4. 確定在要求中傳送的酬載格式。
    5. 如果 Content-Encoding 標頭的值在 支援的編碼清單中,但回應酬載的格式與 Content-Encoding 標頭中指定的編碼不符,這就是問題原因。

      範例:

      curl -v https://HOSTALIAS/test
      

      ***trimmed***
      >
      < HTTP/1.1 200 OK
      < Accept-Ranges: bytes
      < Content-Encoding: gzip
      < Date: Mon, 02 Aug 2021 08:17:35 GMT
      < Transfer-Encoding: chunked
      <
      < response_payload.zip Response Body(not in GZIP format)>
      

      上述回應範例將 gzip 值傳送至 Content-Encoding 標頭,這是 Apigee Edge 中 支援的編碼。不過,response_payload.zip 會以 ZIP 檔案的形式傳送。因此,這個回應失敗,並出現 502 Bad Gateway 錯誤並錯誤代碼:messaging.adaptors.http.flow.DecompressionFailureAtResponse

    訊息處理器記錄

    如何使用訊息處理器記錄進行驗證:

    如果您是私人 Cloud 使用者,則可以使用訊息處理器記錄檔來判斷 HTTP 502 錯誤的相關重要資訊。

    1. 查看訊息處理器記錄:

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

    2. 搜尋特定時間範圍內是否有任何 502 錯誤 (如果問題在過去有發生),或是否有任何回應仍為 502 失敗。您可以使用下列搜尋字串:

      grep -ri "ZipException"
      
    3. 您會在 system.log 中找到類似以下的幾行程式碼:

      情境 1

      情境 #1:當 API 回應含有 Content-Encoding: gzip 標頭時

      2021-08-02 06:50:25,433  NIOThread@2 ERROR HTTP.CLIENT -
      HTTPClient$Context.onInputException() :  ClientInputChannel(ClientChannel[Connected:
      Remote:3.8.1.1:9000 Local:10.0.115.32:41298]@38140 useCount=1 bytesRead=0
      bytesWritten=203 age=469ms  lastIO=0ms  isOpen=true).onExceptionRead exception: {}
      java.util.zip.ZipException: Not in GZIP format
      ---trimmed--
      2021-08-02 06:50:25,433  NIOThread@2 INFO  HTTP.CLIENT -
      HTTPClient$Context.logContextDetails() : Request details : host=null
      path=/folder/testFile method=GET. Channel details : Bytes read=0
      2021-08-02 06:50:25,434  NIOThread@2 ERROR ADAPTORS.HTTP.FLOW -
      AbstractResponseListener.onException() : AbstractResponseListener.onError(HTTPResponse@4806fdab, Not in GZIP format)
      2021-08-02 06:50:25,434  NIOThread@2 INFO  HTTP.SERVICE -
      ExceptionHandler.handleException() : Exception
      java.util.zip.ZipException: Not in GZIP format
      occurred while writing to channel null
      2021-08-02 06:50:25,434  NIOThread@2 INFO  HTTP.SERVICE -
      ExceptionHandler.handleException() : Exception trace:
      java.util.zip.ZipException: Not in GZIP format
      

      上方錯誤訊息中的行 java.util.zip.ZipException: Not in GZIP format 表示雖然 Content-Encoding 指定為 gzip,但回應酬載不會以 GZIP 格式傳送。因此,Apigee Edge 會擲回例外狀況,將含有錯誤代碼 messaging.adaptors.http.flow.DecompressionFailureAtResponse502 狀態碼傳回用戶端應用程式。

      情境 2

      情境 #2:當 API 回應含有 Content-Encoding: deflate

      2021-08-02 06:35:21,215  NIOThread@0 ERROR HTTP.CLIENT -
      HTTPClient$Context.onInputException() :  ClientInputChannel(ClientChannel[Connected:
      Remote:3.8.1.1:9000 Local:192.168.194.140:35224]@36014 useCount=1 bytesRead=0
      bytesWritten=202 age=439ms  lastIO=2ms  isOpen=true).onExceptionRead exception: {}
      java.util.zip.ZipException: incorrect header check
      ---trimmed----
      Caused by:
      java.util.zip.DataFormatException: incorrect header check
      ---trimmed---
      2021-08-02 06:35:21,215  NIOThread@0 INFO  HTTP.CLIENT -
      HTTPClient$Context.logContextDetails() : Request details :
      host=null path=/folder/testFile method=GET. Channel details : Bytes read=0
      2021-08-02 06:35:21,216  NIOThread@0 ERROR ADAPTORS.HTTP.FLOW -
      AbstractResponseListener.onException() : AbstractResponseListener.onError(HTTPResponse@3966e277,
      incorrect header check)
      2021-08-02 06:35:21,216  NIOThread@0 INFO  HTTP.SERVICE -
      ExceptionHandler.handleException() : Exception
      java.util.zip.ZipException: incorrect header check occurred while writing to channel null
      2021-08-02 06:35:21,217  NIOThread@0 INFO  HTTP.SERVICE -
      ExceptionHandler.handleException() : Exception trace:
      java.util.zip.ZipException: incorrect header check
      
      

      上述錯誤訊息中的 java.util.zip.ZipException: incorrect header checkCaused by: java.util.zip.DataFormatException: incorrect header check 行指出回應酬載未以延遲格式傳送,且不符合定義 Content-Encoding 標頭中指定的編碼。因此,Apigee Edge 會擲回例外狀況,將含有錯誤代碼 messaging.adaptors.http.flow.DecompressionFailureAtResponse502 狀態碼傳回用戶端應用程式。

解析度

  1. 如果 Apigee Edge 和後端伺服器中的 API Proxy 流程中不需要經過壓縮的回應酬載,請「不要」傳送標頭 Content-Encoding。如果您需要壓縮回應酬載,請前往步驟 2。
  2. 如果您需要壓縮回應酬載,請確認後端伺服器一律傳送下列項目:
    • 回應中 Content-Encoding 標頭值的任何 支援的編碼
    • Apigee Edge 支援的格式回應酬載與 Content-Encoding 標頭中指定的編碼格式相符
  3. 在上述範例中,回應酬載採用 ZIP 格式,但回應標頭指定了 Content-Encoding: gzip。如要解決這個問題,請以 Content-Encoding: gzip 傳送回應標頭,並以 gzip 格式傳送回應酬載:
    curl -v https://HOSTALIAS/v1/test
    
    >
    < HTTP/1.1 200 OK
    < Accept-Ranges: bytes
    < Content-Encoding: gzip
    < Date: Mon, 02 Aug 2021 08:17:35 GMT
    < Transfer-Encoding: chunked
    <
    < response_payload.gz Response Body(in GZIP format)>
    

規格

根據以下 RFC 規格,Apigee Edge 以狀態碼 502 Bad Gateway 回應,錯誤代碼為 messaging.adaptors.http.flow.DecompressionFailureAtResponse

規格
RFC 7231 第 6.5.1 節
RFC 7231 第 3.1.2.2 節

如果仍需要 Apigee 支援團隊的任何協助,請參閱「 必須收集診斷資訊」。

必須收集診斷資訊

收集下列診斷資訊,然後與 Apigee Edge 支援團隊聯絡:

如果您是公開雲端使用者,請提供下列資訊:

  • 機構組織名稱
  • 環境名稱
  • API Proxy 名稱
  • 完成用來重現 502 錯誤的 curl 指令
  • API 回應的追蹤檔

如果您是 Private Cloud 使用者,請提供下列資訊:

  • 針對失敗回應觀察到完整錯誤訊息
  • 環境名稱
  • API Proxy 套裝組合
  • API 回應的追蹤檔
  • NGINX 存取記錄檔 /opt/apigee/var/log/edge-router/nginx/ORG~ENV.PORT#_access_log

    其中:系統會將 ORGENVPORT# 替換為實際值。

  • 訊息處理器系統記錄 /opt/apigee/var/log/edge-message-processor/logs/system.log