1
0
mirror of https://github.com/golang/go synced 2024-11-21 17:04:42 -07:00

Update server.go

The original writing method may cause deadlocks as it affects lock copies
This commit is contained in:
winter-hu 2024-07-09 12:30:38 +08:00 committed by GitHub
parent 87ec2c959c
commit 14afcb3dc5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -315,6 +315,8 @@ func (c *conn) hijacked() bool {
// c.mu must be held.
func (c *conn) hijackLocked() (rwc net.Conn, buf *bufio.ReadWriter, err error) {
c.mu.Lock()
defer c.mu.Unlock()
if c.hijackedv {
return nil, nil, ErrHijacked
}
@ -2161,13 +2163,9 @@ func (w *response) Hijack() (rwc net.Conn, buf *bufio.ReadWriter, err error) {
w.cw.flush()
}
c := w.conn
c.mu.Lock()
defer c.mu.Unlock()
// Release the bufioWriter that writes to the chunk writer, it is not
// used after a connection has been hijacked.
rwc, buf, err = c.hijackLocked()
rwc, buf, err = w.conn.hijackLocked()
if err == nil {
putBufioWriter(w.w)
w.w = nil