Skip to content

Commit

Permalink
Merge branch 'ethereum:master' into portal
Browse files Browse the repository at this point in the history
  • Loading branch information
GrapeBaBa authored Jul 23, 2024
2 parents f96f5d7 + 57e6627 commit 7a735f6
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions rpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ package rpc

import (
"context"
"errors"
"io"
"net"
"sync"
"sync/atomic"

Expand Down Expand Up @@ -151,8 +153,8 @@ func (s *Server) serveSingleRequest(ctx context.Context, codec ServerCodec) {

reqs, batch, err := codec.readBatch()
if err != nil {
if err != io.EOF {
resp := errorMessage(&invalidMessageError{"parse error"})
if msg := messageForReadError(err); msg != "" {
resp := errorMessage(&invalidMessageError{msg})
codec.writeJSON(ctx, resp, true)
}
return
Expand All @@ -164,6 +166,20 @@ func (s *Server) serveSingleRequest(ctx context.Context, codec ServerCodec) {
}
}

func messageForReadError(err error) string {
var netErr net.Error
if errors.As(err, &netErr) {
if netErr.Timeout() {
return "read timeout"
} else {
return "read error"
}
} else if err != io.EOF {
return "parse error"
}
return ""
}

// Stop stops reading new requests, waits for stopPendingRequestTimeout to allow pending
// requests to finish, then closes all codecs which will cancel pending requests and
// subscriptions.
Expand Down

0 comments on commit 7a735f6

Please sign in to comment.