dubbo-go icon indicating copy to clipboard operation
dubbo-go copied to clipboard

The leakage of goroutines occurs when using generic

Open mimose opened this issue 1 year ago • 4 comments

Environment

  • Server:
  • Client: v3.1.1
  • Protocol:
  • Registry: Nacos

Issue description

When using genric for requests, it can be observed that the number of goroutines keeps increasing with initialization.

init like:

        refConfig := config.ReferenceConfig{
		InterfaceName: genericConfig.InterfaceName,
		Protocol:      genericConfig.Protocol,
		RegistryIDs:   genericConfig.RegistryIds,
		Cluster:       genericConfig.Cluster,
		Group:   genericConfig.Group,
		Version: genericConfig.Version,
		Generic:        "true",
		RequestTimeout: genericConfig.RequestTimeout,
	}
	// init
	err := refConfig.Init(gRootConfig)
	if err != nil {
		return err
	}
	// load
	refConfig.GenericLoad(genericConfig.InterfaceName)
	// to service
	genericService := refConfig.GetRPCService().(*generic.GenericService)
        // do invoke
        // ....
        // after invoke, i close it
        refConfig.GetInvoker().Destroy()

the flame like this, it from nacosListener image

mimose avatar Jul 17 '24 07:07 mimose

In generic scenario, the best practice is to cache ReferenceConfig instances for reuse because the initialization of ReferenceConfig is relatively heavy.

chickenlj avatar Jul 18 '24 03:07 chickenlj

@chickenlj 是的,我在初始化完成后会进行缓存,但缓存会有有效时间,失效后会重新初始化。在失效时我会进行invoker的destroy,但这个destroy看结果似乎不会关闭初始化时开启的nacosListener。导致goroutine不停上涨

mimose avatar Jul 22 '24 02:07 mimose

I see, we will take a look at this issue.

chickenlj avatar Jul 22 '24 02:07 chickenlj

@chickenlj hi, is there any update? I'm happy to provide any additional information that might be helpful.

mimose avatar Aug 02 '24 10:08 mimose

improve it in weekly https://github.com/apache/dubbo-go/discussions/2770

AlexStocks avatar Dec 29 '24 12:12 AlexStocks

luoyingtao 跟 @chickenlj 交流下

AlexStocks avatar Feb 16 '25 12:02 AlexStocks