Skip to content

Commit

Permalink
fix blocking issue if use async call(Go) and not set done
Browse files Browse the repository at this point in the history
  • Loading branch information
smallnest committed Dec 28, 2023
1 parent 3e0d3b0 commit bb9fb77
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions client/xclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,11 @@ func (c *xClient) Go(ctx context.Context, serviceMethod string, args interface{}
if share.Trace {
log.Debugf("selected a client %s for %s.%s, args: %+v in case of xclient Go", client.RemoteAddr(), c.servicePath, serviceMethod, args)
}

if done == nil {
done = make(chan *Call, 10)
}

return client.Go(ctx, c.servicePath, serviceMethod, args, reply, done), nil
}

Expand Down Expand Up @@ -655,9 +660,36 @@ func (c *xClient) Call(ctx context.Context, serviceMethod string, args interface

// Oneshot invokes the named function, ** DOEST NOT ** wait for it to complete, and returns immediately.
func (c *xClient) Oneshot(ctx context.Context, serviceMethod string, args interface{}) error {
_, err := c.Go(ctx, serviceMethod, args, nil, nil)
if c.isShutdown {
return ErrXClientShutdown
}

return err
if c.auth != "" {
metadata := ctx.Value(share.ReqMetaDataKey)
if metadata == nil {
metadata = map[string]string{}
ctx = context.WithValue(ctx, share.ReqMetaDataKey, metadata)
}
m := metadata.(map[string]string)
m[share.AuthKey] = c.auth
}

ctx = setServerTimeout(ctx)

if share.Trace {
log.Debugf("select a client for %s.%s, args: %+v in case of xclient Go", c.servicePath, serviceMethod, args)
}
_, client, err := c.selectClient(ctx, c.servicePath, serviceMethod, args)
if err != nil {
return err
}
if share.Trace {
log.Debugf("selected a client %s for %s.%s, args: %+v in case of xclient Go", client.RemoteAddr(), c.servicePath, serviceMethod, args)
}

client.Go(ctx, c.servicePath, serviceMethod, args, nil, nil)

return nil
}

func uncoverError(err error) bool {
Expand Down

0 comments on commit bb9fb77

Please sign in to comment.