From 9963c32d4fb9ef95f9ca22292d1641e6e9dd976c Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Tue, 31 Jan 2023 20:35:44 -0600 Subject: [PATCH] Only count when bytes actually read --- internal/nbconn/nbconn.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/nbconn/nbconn.go b/internal/nbconn/nbconn.go index 6a97511a..61b610a4 100644 --- a/internal/nbconn/nbconn.go +++ b/internal/nbconn/nbconn.go @@ -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.