Skip to content

Commit c26a23d

Browse files
committed
netconn: Avoid returning 0, nil in NetConn.Read
Closes #367
1 parent a02cbef commit c26a23d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

netconn.go

+8
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ func (nc *netConn) Read(p []byte) (int, error) {
141141
nc.readMu.forceLock()
142142
defer nc.readMu.unlock()
143143

144+
return nc.read(p)
145+
}
146+
147+
func (nc *netConn) read(p []byte) (int, error) {
144148
if atomic.LoadInt64(&nc.readExpired) == 1 {
145149
return 0, fmt.Errorf("failed to read: %w", context.DeadlineExceeded)
146150
}
@@ -171,6 +175,10 @@ func (nc *netConn) Read(p []byte) (int, error) {
171175
if err == io.EOF {
172176
nc.reader = nil
173177
err = nil
178+
if n == 0 {
179+
// Avoid returning 0, nil. #367
180+
n, err = nc.read(p)
181+
}
174182
}
175183
return n, err
176184
}

0 commit comments

Comments
 (0)