Skip to content

net/http/httputil: request may be killed by mistake by former cancel request in ReverseProxy.ServeHTTP #16041

@xuzhaokui

Description

@xuzhaokui

Hi:

  1. What version of Go are you using (go version)?

    go version go1.6.2 darwin/amd64

  2. What operating system and processor architecture are you using (go env)?

    GOARCH="amd64"
    GOOS="darwin"

  3. What did you do?

    1. serving proxy requests by httputil.ReverseProxy
    2. about 10% of request are canceled by clients
  4. What did you expect to see?

    no requests should occur any unexpected error.

  5. What did you see instead?

    some normal(non-canceled) requests are affected by their former requests which are canceled by clients.

Finally I find this:

There is a goroutine here(in ServeHTTP): goroutine

this goroutine is used for receiving clientGone or reqDone signal, however, we assume this scene:

  1. ServeHTTP start handling Request A(using underlying net.Conn C)
  2. Request A was canceled by its client (sending sig to clientGone)
  3. RoundTrip return error(may be use of closed network connection in go1.6- or other error in go1.6+)
  4. ServeHTTP start to return and defer close(reqDone) is executed(close is non-block, so ServeHTTP may be return before the goroutine A receive close signal, but goroutine A is still alive)
  5. net/http put net.Conn C to IdleConn
  6. Request B arrived and net/http pick the same underlying net.Conn C
  7. ServeHTTP start handling Request B (using the same underlying net.Conn C)
  8. goroutine A got signal clientGone first, and then do CancelRequest which will close net.Conn C
  9. Request B's RoundTrip return error cause its underlying conn is closed

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions