The leakage of goroutines occurs when using generic
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
In generic scenario, the best practice is to cache ReferenceConfig instances for reuse because the initialization of ReferenceConfig is relatively heavy.
@chickenlj 是的,我在初始化完成后会进行缓存,但缓存会有有效时间,失效后会重新初始化。在失效时我会进行invoker的destroy,但这个destroy看结果似乎不会关闭初始化时开启的nacosListener。导致goroutine不停上涨
I see, we will take a look at this issue.
@chickenlj hi, is there any update? I'm happy to provide any additional information that might be helpful.
improve it in weekly https://github.com/apache/dubbo-go/discussions/2770
luoyingtao 跟 @chickenlj 交流下