Merge pull request #797 from RichardLindhout/patch-1

Do not log error when EOS is being written on an EOF socket
This commit is contained in:
Asim Aslam 2019-09-27 15:18:35 +01:00 committed by GitHub
commit da572041ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,6 +3,7 @@ package server
import (
"context"
"fmt"
"io"
"net"
"runtime/debug"
"sort"
@ -300,17 +301,21 @@ func (s *rpcServer) ServeConn(sock transport.Socket) {
defer psock.Close()
// serve the actual request using the request router
if err := r.ServeRequest(ctx, request, response); err != nil {
if serveRequestError := r.ServeRequest(ctx, request, response); serveRequestError != nil {
// write an error response
err = rcodec.Write(&codec.Message{
writeError := rcodec.Write(&codec.Message{
Header: msg.Header,
Error: err.Error(),
Error: serveRequestError.Error(),
Type: codec.Error,
}, nil)
// could not write the error response
if err != nil {
log.Logf("rpc: unable to write error response: %v", err)
// if the server request is an EOS error we let the socket know
// sometimes the socket is already closed on the other side, so we can ignore that error
alreadyClosed := serveRequestError == lastStreamResponseError && writeError == io.EOF
// could not write error response
if writeError != nil && !alreadyClosed {
log.Logf("rpc: unable to write error response: %v", writeError)
}
}