Commit ab578e12 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys Committed by Rob Pike

net/rpc: log I/O and internal errors only if debugLog is set.

Fixes #6367.

R=rsc, r
CC=golang-dev
https://golang.org/cl/13395047
parent 765479cc
...@@ -161,7 +161,7 @@ func (client *Client) input() { ...@@ -161,7 +161,7 @@ func (client *Client) input() {
} }
client.mutex.Unlock() client.mutex.Unlock()
client.sending.Unlock() client.sending.Unlock()
if err != io.EOF && !closing { if debugLog && err != io.EOF && !closing {
log.Println("rpc: client protocol error:", err) log.Println("rpc: client protocol error:", err)
} }
} }
...@@ -173,8 +173,10 @@ func (call *Call) done() { ...@@ -173,8 +173,10 @@ func (call *Call) done() {
default: default:
// We don't want to block here. It is the caller's responsibility to make // We don't want to block here. It is the caller's responsibility to make
// sure the channel has enough buffer space. See comment in Go(). // sure the channel has enough buffer space. See comment in Go().
if debugLog {
log.Println("rpc: discarding Call reply due to insufficient Done chan capacity") log.Println("rpc: discarding Call reply due to insufficient Done chan capacity")
} }
}
} }
// NewClient returns a new Client to handle requests to the // NewClient returns a new Client to handle requests to the
......
...@@ -38,6 +38,9 @@ const debugText = `<html> ...@@ -38,6 +38,9 @@ const debugText = `<html>
var debug = template.Must(template.New("RPC debug").Parse(debugText)) var debug = template.Must(template.New("RPC debug").Parse(debugText))
// If set, print log statements for internal and I/O errors.
var debugLog = false
type debugMethod struct { type debugMethod struct {
Type *methodType Type *methodType
Name string Name string
......
...@@ -266,6 +266,7 @@ func (server *Server) register(rcvr interface{}, name string, useName bool) erro ...@@ -266,6 +266,7 @@ func (server *Server) register(rcvr interface{}, name string, useName bool) erro
if len(s.method) == 0 { if len(s.method) == 0 {
str := "" str := ""
// To help the user, see if a pointer receiver would work. // To help the user, see if a pointer receiver would work.
method := suitableMethods(reflect.PtrTo(s.typ), false) method := suitableMethods(reflect.PtrTo(s.typ), false)
if len(method) != 0 { if len(method) != 0 {
...@@ -357,7 +358,7 @@ func (server *Server) sendResponse(sending *sync.Mutex, req *Request, reply inte ...@@ -357,7 +358,7 @@ func (server *Server) sendResponse(sending *sync.Mutex, req *Request, reply inte
resp.Seq = req.Seq resp.Seq = req.Seq
sending.Lock() sending.Lock()
err := codec.WriteResponse(resp, reply) err := codec.WriteResponse(resp, reply)
if err != nil { if debugLog && err != nil {
log.Println("rpc: writing response:", err) log.Println("rpc: writing response:", err)
} }
sending.Unlock() sending.Unlock()
...@@ -435,7 +436,7 @@ func (server *Server) ServeCodec(codec ServerCodec) { ...@@ -435,7 +436,7 @@ func (server *Server) ServeCodec(codec ServerCodec) {
for { for {
service, mtype, req, argv, replyv, keepReading, err := server.readRequest(codec) service, mtype, req, argv, replyv, keepReading, err := server.readRequest(codec)
if err != nil { if err != nil {
if err != io.EOF { if debugLog && err != io.EOF {
log.Println("rpc:", err) log.Println("rpc:", err)
} }
if !keepReading { if !keepReading {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment