diff --git a/internal/jsonrpc2/jsonrpc2.go b/internal/jsonrpc2/jsonrpc2.go index 88a1f4910a..c59d4ad56c 100644 --- a/internal/jsonrpc2/jsonrpc2.go +++ b/internal/jsonrpc2/jsonrpc2.go @@ -22,9 +22,6 @@ import ( const ( // ErrIdleTimeout is returned when serving timed out waiting for new connections. ErrIdleTimeout = constError("timed out waiting for new connections") - - // ErrDisconnected signals that the stream or connection exited normally. - ErrDisconnected = constError("disconnected") ) // Conn is a JSON RPC 2 client server connection. diff --git a/internal/jsonrpc2/jsonrpc2_test.go b/internal/jsonrpc2/jsonrpc2_test.go index b7232caa70..d9cc307b5d 100644 --- a/internal/jsonrpc2/jsonrpc2_test.go +++ b/internal/jsonrpc2/jsonrpc2_test.go @@ -126,7 +126,7 @@ func run(ctx context.Context, t *testing.T, withHeaders bool, r io.ReadCloser, w wg.Done() }() err := conn.Run(ctx, testHandler(*logRPC)) - if err != nil && !errors.Is(err, jsonrpc2.ErrDisconnected) { + if err != nil && !errors.Is(err, io.EOF) && !errors.Is(err, io.ErrClosedPipe) { t.Errorf("Stream failed: %v", err) } }() diff --git a/internal/jsonrpc2/stream.go b/internal/jsonrpc2/stream.go index dc2ebd4a31..c7d73f7277 100644 --- a/internal/jsonrpc2/stream.go +++ b/internal/jsonrpc2/stream.go @@ -52,9 +52,6 @@ func (s *plainStream) Read(ctx context.Context) (Message, int64, error) { } var raw json.RawMessage if err := s.in.Decode(&raw); err != nil { - if err == io.EOF { - return nil, 0, ErrDisconnected - } return nil, 0, err } msg, err := DecodeMessage(raw) @@ -104,12 +101,8 @@ func (s *headerStream) Read(ctx context.Context) (Message, int64, error) { for { line, err := s.in.ReadString('\n') total += int64(len(line)) - if err == io.EOF { - // A normal disconnection will terminate with EOF before the next header. - return nil, total, ErrDisconnected - } if err != nil { - return nil, total, fmt.Errorf("failed reading header line %q", err) + return nil, total, fmt.Errorf("failed reading header line: %w", err) } line = strings.TrimSpace(line) // check we have a header line