Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在 Triple 协议下,配置最大消息长度无效 (ServiceConfig 中的 GrpcMaxMessageSize 配置项) #2487

Open
EarlyBedEarlyUp opened this issue Nov 6, 2023 · 0 comments

Comments

@EarlyBedEarlyUp
Copy link

Environment

  • Server: Dubbo-go, v3.0.5
  • Client: Dubbo-go, v3.0.5
  • Protocol: Triple
  • Registry: Nacos, v2.2.3

Issue description

如题,通过下面的配置方式初始化dubbo-go,最大消息长度仍然是默认的4M

func InitDubbo(moduleName, environmentName, groupName, nacosUrl, nameSpace string, nacosPort int) {
	dataId := fmt.Sprintf("%s-%s", moduleName, environmentName)
	nacosAddress := fmt.Sprintf("%s:%d", nacosUrl, nacosPort)
	initProvider()

	// 单独给这个服务设置grpc最大值
	fileServiceConfig := config.NewServiceConfigBuilder().Build()
	fileServiceConfig.GrpcMaxMessageSize = 100

	rootConfig := config.NewRootConfigBuilder().
		SetProvider(config.NewProviderConfigBuilder().
			AddService("FileProvider", fileServiceConfig).Build()).
		SetConfigCenter(config.NewConfigCenterConfigBuilder().
			SetProtocol("nacos").SetAddress(nacosAddress).SetNamespace(nameSpace).
			SetDataID(dataId).SetGroup(groupName).Build()).
		Build()
	if err := config.Load(config.WithRootConfig(rootConfig)); err != nil {
		panic("Init Dubbo Error Please Check Config")
	}
}

打断点调试后发现在 /protocol/dubbo3/dubbo3_protocol.goopenServer 方法中虽然有下列配置最大消息的代码,但是只有第一个 Provider 的配置才会走这段代码,而注册的第一个服务是 ServerReflection ,此服务是默认配置,而不是我上述代码的配置。

// openServer open a dubbo3 server, if there is already a service using the same protocol, it returns directly.
func (dp *DubboProtocol) openServer(url *common.URL, tripleCodecType tripleConstant.CodecType) {
	dp.serverLock.Lock()
	defer dp.serverLock.Unlock()
	_, ok := dp.serverMap[url.Location]
	// 此处的判断导致带有 GrpcMaxMessageSize 配置内容的 Provider 被return,无法改变 Triple 的配置
	if ok {
		dp.serverMap[url.Location].RefreshService()
		return
	}

	// ... 省略代码

	if maxCall := url.GetParam(constant.MaxServerRecvMsgSize, ""); maxCall != "" {
		if size, err := strconv.Atoi(maxCall); err == nil && size != 0 {
			opts = append(opts, triConfig.WithGRPCMaxServerRecvMessageSize(size))
		}
	}
	if maxCall := url.GetParam(constant.MaxServerSendMsgSize, ""); maxCall != "" {
		if size, err := strconv.Atoi(maxCall); err == nil && size != 0 {
			opts = append(opts, triConfig.WithGRPCMaxServerSendMessageSize(size))
		}
	}

	// ... 省略代码
}

Logs

断点调试信息

WX20231106-113512

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant