Skip to content

Commit

Permalink
Only count when bytes actually read
Browse files Browse the repository at this point in the history
  • Loading branch information
jackc committed Feb 1, 2023
1 parent 6bc327b commit 9963c32
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion internal/nbconn/nbconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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.
Expand Down

0 comments on commit 9963c32

Please sign in to comment.