http2:服务器发送了GOAWAY并关闭了连接;LastStreamID=1999

huangapple go评论147阅读模式
英文:

http2: server sent GOAWAY and closed the connection; LastStreamID=1999

问题

我有一个for循环,在其中调用了一个从osrm服务器获取响应的函数,一段时间后,ioutil.ReadAll(resp.Body)返回了一个错误,打印出http2: server sent GOAWAY and closed the connection; LastStreamID=1999, ErrCode=NO_ERROR, debug=""

func RequestGET(req string) []byte {

    reqst, err := http.NewRequest("GET", req, nil)
    client := &http.Client{}
    resp, err := client.Do(reqst)
    if err != nil {
        panic(err)
    }
    resp_data, err := ioutil.ReadAll(resp.Body)
    resp.Body.Close()
    if err != nil {
        fmt.Println(err)
    }
    return resp_data
}

resp.Body.Close()不是关闭连接吗?我期望每次都获得一个新的连接。

英文:

I have for loop in which I calling that function that takes response from osrm server, after some time ioutil.ReadAll(resp.Body) returns err that prints http2: server sent GOAWAY and closed the connection; LastStreamID=1999, ErrCode=NO_ERROR, debug=""

func RequestGET(req string) []byte {

    reqst, err := http.NewRequest("GET", req, nil)
    client := &http.Client{}
    resp, err := client.Do(reqst)
    if err != nil {
	    panic(err)
    }
    resp_data, err := ioutil.ReadAll(resp.Body)
    resp.Body.Close()
    if err != nil {
	    fmt.Println(err)
    }
    return resp_data
}

Isn't resp.Body.Close() closes a connection? I expected to get every time a new one.

答案1

得分: 8

服务器由于某种原因关闭了连接;后端关闭、超时等等。除了重试之外,你没有太多可以做的,就像你遇到其他连接错误一样。关于自动重试的问题有一些讨论(https://golang.org/issue/18639),但总体上看,客户端的工作是按预期进行的。

Response.Body.Close 不会关闭连接,否则就会破坏 http1.1 和 http2 使用持久连接的目的。通过读取和关闭响应体,你可以允许连接被 http 客户端重用。

英文:

The server is closing the connection for some reason; the backend closed, timed out, etc. There's not much you can do except retry, just as if you had any other connection error. There is some discussion in a arelated issue (https://golang.org/issue/18639) about retrying this automatically, but it generally looks like the client is working as intended.

Response.Body.Close does not close a connection, otherwise it would defeat the purpose of http1.1 and http2 using persistent connections. Reading and closing the response body is how you allow the connection to be reused by the http client.

答案2

得分: 0

我遇到了一个与发送超过50k的头部的GET请求相关的问题。默认情况下,nginx有一个4k的限制。所以如果你的服务器因为请求头而断开连接,你可能会收到这个消息。

英文:

I had this issue related to a GET request sending a header with more than 50k. By default nginx has a limit of 4k. So if your server is dropping the connection because the request header, you can get this message.

huangapple
  • 本文由 发表于 2017年7月20日 16:17:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/45209168.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定