mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-22 23:13:01 +00:00
drain buffer correctly in httpupgrade (#3428)
* drain buffer correctly in httpupgrade it seems the recently added httupgrade testsuite is causing timeouts on master i have no evidence this is the real issue, but it feels to me that the server could accidentally over-read, and then the encapsulated connection will block forever trying to read data let's test it in CI a couple of times, i don't have a way to reproduce the issue * correctly drain buffer, again
This commit is contained in:
parent
980236f2b6
commit
f8ec93dfdd
@ -24,8 +24,10 @@ type ConnRF struct {
|
|||||||
func (c *ConnRF) Read(b []byte) (int, error) {
|
func (c *ConnRF) Read(b []byte) (int, error) {
|
||||||
if c.First {
|
if c.First {
|
||||||
c.First = false
|
c.First = false
|
||||||
// TODO The bufio usage here is unreliable
|
// create reader capped to size of `b`, so it can be fully drained into
|
||||||
resp, err := http.ReadResponse(bufio.NewReader(c.Conn), c.Req) // nolint:bodyclose
|
// `b` later with a single Read call
|
||||||
|
reader := bufio.NewReaderSize(c.Conn, len(b))
|
||||||
|
resp, err := http.ReadResponse(reader, c.Req) // nolint:bodyclose
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
@ -34,6 +36,8 @@ func (c *ConnRF) Read(b []byte) (int, error) {
|
|||||||
strings.ToLower(resp.Header.Get("Connection")) != "upgrade" {
|
strings.ToLower(resp.Header.Get("Connection")) != "upgrade" {
|
||||||
return 0, newError("unrecognized reply")
|
return 0, newError("unrecognized reply")
|
||||||
}
|
}
|
||||||
|
// drain remaining bufreader
|
||||||
|
return reader.Read(b[:reader.Buffered()])
|
||||||
}
|
}
|
||||||
return c.Conn.Read(b)
|
return c.Conn.Read(b)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user