From 81afa8a34970dc1f5b2a59084a17d1a1a8d248ea Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Fri, 13 Oct 2023 04:30:08 -0700 Subject: [PATCH] netconn: Avoid returning 0, nil in NetConn.Read Closes #367 --- netconn.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/netconn.go b/netconn.go index 74000c9e..e398b4f7 100644 --- a/netconn.go +++ b/netconn.go @@ -141,6 +141,19 @@ func (nc *netConn) Read(p []byte) (int, error) { nc.readMu.forceLock() defer nc.readMu.unlock() + for { + n, err := nc.read(p) + if err != nil { + return n, err + } + if n == 0 { + continue + } + return n, nil + } +} + +func (nc *netConn) read(p []byte) (int, error) { if atomic.LoadInt64(&nc.readExpired) == 1 { return 0, fmt.Errorf("failed to read: %w", context.DeadlineExceeded) }