Skip to content

Commit 0fbe0f6

Browse files
authored
Go: stop RPC client logging expected errors (#609)
* Go: RPC client loop expects stdout close * handle body read errors similarly
1 parent 21504ac commit 0fbe0f6

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

go/internal/jsonrpc2/jsonrpc2.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import (
44
"bufio"
55
"crypto/rand"
66
"encoding/json"
7+
"errors"
78
"fmt"
89
"io"
10+
"os"
911
"reflect"
1012
"sync"
1113
"sync/atomic"
@@ -320,7 +322,7 @@ func (c *Client) readLoop() {
320322
line, err := reader.ReadString('\n')
321323
if err != nil {
322324
// Only log unexpected errors (not EOF or closed pipe during shutdown)
323-
if err != io.EOF && c.running.Load() {
325+
if err != io.EOF && !errors.Is(err, os.ErrClosed) && c.running.Load() {
324326
fmt.Printf("Error reading header: %v\n", err)
325327
}
326328
return
@@ -345,7 +347,10 @@ func (c *Client) readLoop() {
345347
// Read message body
346348
body := make([]byte, contentLength)
347349
if _, err := io.ReadFull(reader, body); err != nil {
348-
fmt.Printf("Error reading body: %v\n", err)
350+
// Only log unexpected errors (not EOF or closed pipe during shutdown)
351+
if err != io.EOF && !errors.Is(err, os.ErrClosed) && c.running.Load() {
352+
fmt.Printf("Error reading body: %v\n", err)
353+
}
349354
return
350355
}
351356

0 commit comments

Comments
 (0)