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

与viper结合时,remote部分的agollo没办法停止 #52

Closed
hulb opened this issue Nov 10, 2020 · 4 comments
Closed

与viper结合时,remote部分的agollo没办法停止 #52

hulb opened this issue Nov 10, 2020 · 4 comments

Comments

@hulb
Copy link

hulb commented Nov 10, 2020

viper-remote部分会在第一次读配置时new一个agollo对象,然后启动notification监听。但是这个agollo目前好像没有停止的方式

@hulb hulb changed the title 与viper结合时,基于轮询的更新机制好像有问题 与viper结合时,remote部分的agollo没办法停止 Nov 10, 2020
@shima-park
Copy link
Owner

确实有这个问题

你的需求是不是只需要启动时读取一次,并不需要持续监听配置
如果是这样的话,有个简单的办法修复,只在Watch时去启动监听。

如果是在Watch后,需要去关闭agollo 就不太好处理,实例被隐藏在viper后面

@hulb
Copy link
Author

hulb commented Nov 11, 2020

也不是,我也需要持续监听配置。只是在主程序退出时希望agollo也可以stop,毕竟有个goroutine在那里。我看remote那里所有的agollo都放在remote.agolloMap里,简单加个退出方法是不是就可以了:

remote.go

func StopAll() {
	agolloMap.Range(func(key, value interface{}) bool {
		value.(agollo.Agollo).Stop()
		return true
	})
}

但是agollo.longPoll会有被hold的情况,这种好像不一定够

@shima-park
Copy link
Owner

主进程退出后,这些监听的goroutine也会消亡,其实不用太在意

这样也考虑过,是可以这么做。longPoll最坏情况下,对应的那个agollo实例,90秒后也会退出,也还好。
主要是viper没要求ConfigManager实现Close方法,绕开它主动关闭,会有些奇怪。

@hulb
Copy link
Author

hulb commented Nov 11, 2020

嗯,我不是太清楚主进程退出后监听goroutine相关的资源会不会被正常回收,stopCh还好,longPoll里面涉及到网络了不是太安心。viper接口里增加Close就好了,我先关issue吧,谢谢您抽空解答。

@hulb hulb closed this as completed Nov 11, 2020
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