Golang-使用Thrift請求後獲得HttpStatus413

Thrift請求後獲得HttpStatus413是什麼鬼?如下會爲你一一解答。服務器

Let's Go!


1.解決方案

  • 本身繼承後從新實現(推薦)
  • 修改thrfit包中SetHeader/Flush方法,增長重置header邏輯
  • 每次都從新建立Thrift鏈接

2.環境

  • Golang version:1.5
  • Linux version:Linux version 2.6.32-279.el6.x86_64 (gcc version 4.4.6 20120305 (Red Hat 4.4.6-4) (GCC) )
  • Os version:CentOS release 6.3 (Final) 2.6.32-279.el6.x86_64
  • Cpu :12
  • Mem :8G
  • 網絡協議:Thrift

3.場景

  • 使用Sync.pool管理調用Thrift的goroutine,減小建立及銷燬goroutine開銷,c爲調用client
c := pool.Get()
    defer pool.Put(c)
    如下爲調用邏輯....

4.問題現象

錯誤信息

  • Client端報Http Status 413
  • Server端無報錯信息

5.問題緣由

1.HttpStatus 413是什麼意思?網絡

HTTP Status 413 (請求實體過大)
服務器沒法處理請求,由於請求實體過大,超出服務器的處理能力。

注意:這裏請求實體過大的意思是包括header和body(一開始定位時只定位了body,就進坑了- -)this

針對該問題主要爲header過大code

2.RPC時會設置header,但對於存在於pool中的goroutine,是Addheader,請看如下代碼,繼承

// Set the HTTP Header for this specific Thrift Transport
// It is important that you first assert the TTransport as a THttpClient type
// like so:
//
// httpTrans := trans.(THttpClient)
// httpTrans.SetHeader("User-Agent","Thrift Client 1.0")
func (p *THttpClient) SetHeader(key string, value string) {
    p.header.Add(key, value)
}

這就是致使出現413的緣由ci

相關文章
相關標籤/搜索