mirror of
https://github.com/smallnest/rpcx.git
synced 2025-11-01 20:02:39 +08:00
don't close the connection if the error is context error
This commit is contained in:
@@ -425,7 +425,9 @@ func (c *xClient) Call(ctx context.Context, serviceMethod string, args interface
|
||||
}
|
||||
}
|
||||
|
||||
c.removeClient(k, client)
|
||||
if uncoverError(err) {
|
||||
c.removeClient(k, client)
|
||||
}
|
||||
client, e = c.getCachedClient(k)
|
||||
}
|
||||
if err == nil {
|
||||
@@ -447,7 +449,9 @@ func (c *xClient) Call(ctx context.Context, serviceMethod string, args interface
|
||||
}
|
||||
}
|
||||
|
||||
c.removeClient(k, client)
|
||||
if uncoverError(err) {
|
||||
c.removeClient(k, client)
|
||||
}
|
||||
//select another server
|
||||
k, client, e = c.selectClient(ctx, c.servicePath, serviceMethod, args)
|
||||
}
|
||||
@@ -487,7 +491,7 @@ func (c *xClient) Call(ctx context.Context, serviceMethod string, args interface
|
||||
}
|
||||
_, err2 := c.Go(ctx, serviceMethod, args, reply2, call2)
|
||||
if err2 != nil {
|
||||
if _, ok := err.(ServiceError); !ok {
|
||||
if uncoverError(err2) {
|
||||
c.removeClient(k, client)
|
||||
}
|
||||
err = err1
|
||||
@@ -513,7 +517,7 @@ func (c *xClient) Call(ctx context.Context, serviceMethod string, args interface
|
||||
default: //Failfast
|
||||
err = c.wrapCall(ctx, client, serviceMethod, args, reply)
|
||||
if err != nil {
|
||||
if _, ok := err.(ServiceError); !ok {
|
||||
if uncoverError(err) {
|
||||
c.removeClient(k, client)
|
||||
}
|
||||
}
|
||||
@@ -522,6 +526,21 @@ func (c *xClient) Call(ctx context.Context, serviceMethod string, args interface
|
||||
}
|
||||
}
|
||||
|
||||
func uncoverError(err error) bool {
|
||||
if _, ok := err.(ServiceError); ok {
|
||||
return false
|
||||
}
|
||||
|
||||
if err == context.DeadlineExceeded {
|
||||
return false
|
||||
}
|
||||
|
||||
if err == context.Canceled {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
func (c *xClient) SendRaw(ctx context.Context, r *protocol.Message) (map[string]string, []byte, error) {
|
||||
if c.isShutdown {
|
||||
return nil, nil, ErrXClientShutdown
|
||||
@@ -566,7 +585,9 @@ func (c *xClient) SendRaw(ctx context.Context, r *protocol.Message) (map[string]
|
||||
}
|
||||
}
|
||||
|
||||
c.removeClient(k, client)
|
||||
if uncoverError(err) {
|
||||
c.removeClient(k, client)
|
||||
}
|
||||
client, e = c.getCachedClient(k)
|
||||
}
|
||||
|
||||
@@ -588,7 +609,9 @@ func (c *xClient) SendRaw(ctx context.Context, r *protocol.Message) (map[string]
|
||||
}
|
||||
}
|
||||
|
||||
c.removeClient(k, client)
|
||||
if uncoverError(err) {
|
||||
c.removeClient(k, client)
|
||||
}
|
||||
//select another server
|
||||
k, client, e = c.selectClient(ctx, r.ServicePath, r.ServiceMethod, r.Payload)
|
||||
}
|
||||
@@ -602,7 +625,7 @@ func (c *xClient) SendRaw(ctx context.Context, r *protocol.Message) (map[string]
|
||||
m, payload, err := client.SendRaw(ctx, r)
|
||||
|
||||
if err != nil {
|
||||
if _, ok := err.(ServiceError); !ok {
|
||||
if uncoverError(err) {
|
||||
c.removeClient(k, client)
|
||||
}
|
||||
}
|
||||
@@ -666,7 +689,9 @@ func (c *xClient) Broadcast(ctx context.Context, serviceMethod string, args inte
|
||||
e := c.wrapCall(ctx, client, serviceMethod, args, reply)
|
||||
done <- (e == nil)
|
||||
if e != nil {
|
||||
c.removeClient(k, client)
|
||||
if uncoverError(err) {
|
||||
c.removeClient(k, client)
|
||||
}
|
||||
err.Append(e)
|
||||
}
|
||||
}()
|
||||
@@ -743,7 +768,9 @@ func (c *xClient) Fork(ctx context.Context, serviceMethod string, args interface
|
||||
}
|
||||
done <- (e == nil)
|
||||
if e != nil {
|
||||
c.removeClient(k, client)
|
||||
if uncoverError(err) {
|
||||
c.removeClient(k, client)
|
||||
}
|
||||
err.Append(e)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user