Only count when bytes actually read

pull/1490/head
Jack Christensen 2023-01-31 20:35:44 -06:00
parent 6bc327b3ce
commit 9963c32d4f
1 changed files with 4 additions and 1 deletions
internal/nbconn

View File

@ -421,7 +421,6 @@ func (c *NetConn) fakeNonblockingRead(b []byte) (n int, err error) {
// already in Go or the OS's receive buffer.
if c.fakeNonBlockingShortReadCount < 5 && len(b) > 0 {
b = b[:1]
c.fakeNonBlockingShortReadCount++
}
startTime := time.Now()
@ -436,6 +435,10 @@ func (c *NetConn) fakeNonblockingRead(b []byte) (n int, err error) {
if err == nil && c.fakeNonblockingReadWaitDuration > minNonblockingReadWaitDuration {
endTime := time.Now()
if n > 0 && c.fakeNonBlockingShortReadCount < 5 {
c.fakeNonBlockingShortReadCount++
}
// The wait duration should be 2x the fastest read that has occurred. This should give reasonable assurance that
// a Read deadline will not block a read before it has a chance to read data already in Go or the OS's receive
// buffer.