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

The leakage of goroutines occurs when using generic #2709

Open
mimose opened this issue Jul 17, 2024 · 4 comments
Open

The leakage of goroutines occurs when using generic #2709

mimose opened this issue Jul 17, 2024 · 4 comments

Comments

@mimose
Copy link

mimose commented Jul 17, 2024

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

@chickenlj
Copy link
Contributor

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

@mimose
Copy link
Author

mimose commented Jul 22, 2024

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

@chickenlj
Copy link
Contributor

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

@mimose
Copy link
Author

mimose commented Aug 2, 2024

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

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

2 participants