Skip to content

Commit 6447404

Browse files
committed
fix(go-nats): report EOF
Signed-off-by: Roman Volosatovs <[email protected]>
1 parent bde733e commit 6447404

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

go/nats/client.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"io"
78
"log/slog"
89
"sync"
910
"sync/atomic"
@@ -258,6 +259,9 @@ func (r *streamReader) Read(p []byte) (int, error) {
258259
if err != nil {
259260
return 0, err
260261
}
262+
if len(msg.Data) == 0 {
263+
return 0, io.EOF
264+
}
261265
n := copy(p, msg.Data)
262266
r.buf = msg.Data[n:]
263267
return n, nil
@@ -270,18 +274,16 @@ func (r *streamReader) ReadByte() (byte, error) {
270274
r.buf = r.buf[1:]
271275
return b, nil
272276
}
273-
for {
274-
slog.Debug("receiving next byte chunk")
275-
msg, err := r.sub.NextMsgWithContext(r.ctx)
276-
if err != nil {
277-
return 0, err
278-
}
279-
if len(msg.Data) == 0 {
280-
continue
281-
}
282-
r.buf = msg.Data[1:]
283-
return msg.Data[0], nil
277+
slog.Debug("receiving next byte chunk")
278+
msg, err := r.sub.NextMsgWithContext(r.ctx)
279+
if err != nil {
280+
return 0, err
281+
}
282+
if len(msg.Data) == 0 {
283+
return 0, io.EOF
284284
}
285+
r.buf = msg.Data[1:]
286+
return msg.Data[0], nil
285287
}
286288

287289
func (r *streamReader) Close() (err error) {

0 commit comments

Comments
 (0)