Skip to content

客户端方法重试次数跟 java 实现不一样 #2550

Closed
@zhaoyunxing92

Description

Environment

  • Server: Dubbo-go, v3.1.0
  • Client: Dubbo-go, v3.1.0
  • Protocol: dubbo
  • Registry: zk

Issue description

两边实现不一样导致客户端重试计算出来值不一样

Java

    private int calculateInvokeTimes(String methodName) {
        int len = getUrl().getMethodParameter(methodName, RETRIES_KEY, DEFAULT_RETRIES) + 1;
        RpcContext rpcContext = RpcContext.getClientAttachment();
        Object retry = rpcContext.getObjectAttachment(RETRIES_KEY);
        if (retry instanceof Number) {
            len = ((Number) retry).intValue() + 1;
            rpcContext.removeAttachment(RETRIES_KEY);
        }
        if (len <= 0) {
            len = 1;
        }

        return len;
    }

Go

func getRetries(invokers []protocol.Invoker, methodName string) int {
	if len(invokers) <= 0 {
		return constant.DefaultRetriesInt
	}

	url := invokers[0].GetURL()
	// get reties
	retriesConfig := url.GetParam(constant.RetriesKey, constant.DefaultRetries)
	// Get the service method loadbalance config if have
	if v := url.GetMethodParam(methodName, constant.RetriesKey, ""); len(v) != 0 {
		retriesConfig = v
	}

	retries, err := strconv.Atoi(retriesConfig)
	if err != nil || retries < 0 {
		logger.Error("Your retries config is invalid,pls do a check. And will use the default retries configuration instead.")
		retries = constant.DefaultRetriesInt
	}

	if retries > len(invokers) {
		retries = len(invokers)
	}
	return retries
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions