1
0
mirror of https://github.com/golang/go synced 2024-11-25 07:17:56 -07:00

net/http: fix hijack hang at abortPendingRead

When concurrent many http requests which need hijack the connenction,
hijack may hang at abortPendingRead() on cr.cond.Wait().

The read can be from readRequest() from conn.serve() or
w.conn.r.startBackgroundRead(). especially in startBackgroundRead()
which always set the deadline time.Time{}.

This problem seems easy reproduce on arm.

Signed-off-by: jingrui <jingrui@huawei.com>
This commit is contained in:
jingrui 2021-05-20 09:18:27 +08:00
parent 6c1c055d1e
commit 78770c121e

View File

@ -736,9 +736,25 @@ func (cr *connReader) abortPendingRead() {
}
cr.aborted = true
cr.conn.rwc.SetReadDeadline(aLongTimeAgo)
for cr.inRead {
cr.cond.Wait()
}
done := make(chan struct{})
go func() {
for cr.inRead {
cr.cond.Wait()
}
close(done)
}()
func() {
for {
select {
case <-done:
return
case <-time.After(100*time.Millisecond):
cr.conn.rwc.SetReadDeadline(aLongTimeAgo)
}
}
}()
cr.conn.rwc.SetReadDeadline(time.Time{})
}