mirror of
https://github.com/golang/go
synced 2024-11-18 10:54:40 -07:00
internal/jsonrpc2: remove jsonrpc2.ErrDisconnected
It was not very useful, it basically renamed io.EOF under some limited circumstances, and was only there for the befit of tests. Instead, the test now checks io.EOF directly, but also checks for io.ErrClosedPipe which was also happening. We also make sure we wrap errors rather than replacing them. This prevents some weird random test failures due to races in the way they were closed. Change-Id: I236b03ac5ba16bf763299b95d882cf58b1f74776 Reviewed-on: https://go-review.googlesource.com/c/tools/+/230303 Run-TryBot: Ian Cottrell <iancottrell@google.com> Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
parent
a90b7300be
commit
9ea0146da6
@ -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.
|
||||
|
@ -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)
|
||||
}
|
||||
}()
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user