From aba29eab01c9054c9f8cce9ccee306b674bdf71f Mon Sep 17 00:00:00 2001 From: duanhf2012 Date: Thu, 2 Apr 2020 16:47:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96rpc=E9=9D=9E=E5=BC=82?= =?UTF-8?q?=E6=AD=A5=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rpc/client.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/rpc/client.go b/rpc/client.go index ed261a0..60db410 100644 --- a/rpc/client.go +++ b/rpc/client.go @@ -6,6 +6,7 @@ import ( "github.com/duanhf2012/origin/network" "math" "reflect" + "runtime" "strings" "sync" "time" @@ -157,6 +158,15 @@ type RpcResponse struct { func (slf *Client) Run(){ + defer func() { + if r := recover(); r != nil { + buf := make([]byte, 4096) + l := runtime.Stack(buf, false) + err := fmt.Errorf("%v: %s\n", r, buf[:l]) + log.Error("core dump info:%+v",err) + } + }() + for { bytes,err := slf.conn.ReadMsg() if err != nil { @@ -193,7 +203,7 @@ func (slf *Client) Run(){ v.Err= respone.Err } - if v.callback.IsValid() { + if v.callback!=nil && v.callback.IsValid() { v.rpcHandler.(*RpcHandler).callResponeCallBack<-v }else{ v.done <- v