This commit is contained in:
Xargin 2025-06-20 15:36:50 -04:00 committed by GitHub
commit e193f59b72
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 0 deletions

View File

@ -836,6 +836,14 @@ func (c *Conn) readFromUntil(r io.Reader, n int) error {
// "predict" closeNotify alerts.
c.rawInput.Grow(needs + bytes.MinRead)
_, err := c.rawInput.ReadFrom(&atLeastReader{r, int64(needs)})
// Read timeout, and we do not get any data, connection is idle,
// we should replace rawInput buffer with a small one
if e, ok := err.(net.Error); ok && e.Timeout() &&
c.rawInput.Len() == 0 && c.rawInput.Cap() > 4*bytes.MinRead {
c.rawInput = *bytes.NewBuffer(make([]byte, 0, bytes.MinRead))
}
return err
}