Skip to content

Commit

Permalink
fix apache#2546,change timeout of DubboInvoker from Milliseconds to N…
Browse files Browse the repository at this point in the history
…anoseconds(apache#2552)
  • Loading branch information
Jafeyyu authored and FinalT committed Jan 10, 2024
1 parent 2dd66e9 commit aebc1f5
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions protocol/dubbo/dubbo_invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,21 +163,22 @@ func (di *DubboInvoker) Invoke(ctx context.Context, ivc protocol.Invocation) pro

// get timeout including methodConfig
func (di *DubboInvoker) getTimeout(ivc *invocation.RPCInvocation) time.Duration {
methodName := ivc.MethodName()
if di.GetURL().GetParamBool(constant.GenericKey, false) {
methodName = ivc.Arguments()[0].(string)
}
timeout := di.GetURL().GetParam(strings.Join([]string{constant.MethodKeys, methodName, constant.TimeoutKey}, "."), "")
if len(timeout) != 0 {
if t, err := time.ParseDuration(timeout); err == nil {
// config timeout into attachment
ivc.SetAttachment(constant.TimeoutKey, strconv.Itoa(int(t.Milliseconds())))
return t
timeout := di.timeout //default timeout
if attachTimeout, ok := ivc.GetAttachment(constant.TimeoutKey); ok { //check invocation timeout
timeout, _ = time.ParseDuration(attachTimeout)
} else { // check method timeout
methodName := ivc.MethodName()
if di.GetURL().GetParamBool(constant.GenericKey, false) {
methodName = ivc.Arguments()[0].(string)
}
mTimeout := di.GetURL().GetParam(strings.Join([]string{constant.MethodKeys, methodName, constant.TimeoutKey}, "."), "")
if len(mTimeout) != 0 {
timeout, _ = time.ParseDuration(mTimeout)
}
}
// set timeout into invocation at method level
ivc.SetAttachment(constant.TimeoutKey, strconv.Itoa(int(di.timeout.Milliseconds())))
return di.timeout
// set timeout into invocation
ivc.SetAttachment(constant.TimeoutKey, strconv.Itoa(int(timeout.Nanoseconds())))
return timeout
}

func (di *DubboInvoker) IsAvailable() bool {
Expand Down

0 comments on commit aebc1f5

Please sign in to comment.