-
-
Notifications
You must be signed in to change notification settings - Fork 199
fix: serverIPListComponent not close when invoke Client close #350
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
Changes from all commits
9ede894
bee9f11
ecb8990
3abb5d5
0b2d6bf
94008e0
44fc4fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,7 +87,7 @@ type internalClient struct { | |
| initAppConfigFunc func() (*config.AppConfig, error) | ||
| appConfig *config.AppConfig | ||
| cache *storage.Cache | ||
| configComponent *notify.ConfigComponent | ||
| components []component.Stoppable | ||
| } | ||
|
|
||
| func (c *internalClient) getAppConfig() config.AppConfig { | ||
|
|
@@ -121,8 +121,10 @@ func StartWithConfig(loadAppConfig func() (*config.AppConfig, error)) (Client, e | |
|
|
||
| c.cache = storage.CreateNamespaceConfig(appConfig.NamespaceName) | ||
| appConfig.Init() | ||
|
|
||
| serverlist.InitSyncServerIPList(c.getAppConfig) | ||
| // start ipList component | ||
| serverIPListComponent := serverlist.NewSyncServerIPListComponent(c.getAppConfig) | ||
| go component.StartRefreshConfig(serverIPListComponent) | ||
| c.appendComponent(serverIPListComponent) | ||
|
|
||
| //first sync | ||
| configs := syncApolloConfig.Sync(c.getAppConfig) | ||
|
|
@@ -137,11 +139,9 @@ func StartWithConfig(loadAppConfig func() (*config.AppConfig, error)) (Client, e | |
| log.Debug("init notifySyncConfigServices finished") | ||
|
|
||
| //start long poll sync config | ||
| configComponent := ¬ify.ConfigComponent{} | ||
| configComponent.SetAppConfig(c.getAppConfig) | ||
| configComponent.SetCache(c.cache) | ||
| configComponent := notify.NewConfigComponent(c.getAppConfig, c.cache) | ||
| go component.StartRefreshConfig(configComponent) | ||
| c.configComponent = configComponent | ||
| c.appendComponent(configComponent) | ||
|
|
||
| log.Info("agollo start finished ! ") | ||
|
|
||
|
|
@@ -269,6 +269,10 @@ func (c *internalClient) getConfigValue(key string) interface{} { | |
| return value | ||
| } | ||
|
|
||
| func (c *internalClient) appendComponent(comp component.Stoppable) { | ||
| c.components = append(c.components, comp) | ||
| } | ||
|
|
||
| // AddChangeListener 增加变更监控 | ||
| func (c *internalClient) AddChangeListener(listener storage.ChangeListener) { | ||
| c.cache.AddChangeListener(listener) | ||
|
|
@@ -289,7 +293,9 @@ func (c *internalClient) UseEventDispatch() { | |
| c.AddChangeListener(storage.UseEventDispatch()) | ||
| } | ||
|
|
||
| // Close 停止轮询 | ||
| // Close stop components | ||
| func (c *internalClient) Close() { | ||
| c.configComponent.Stop() | ||
| for _, comp := range c.components { | ||
| comp.Stop() | ||
| } | ||
| } | ||
|
Comment on lines
297
to
301
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The appendComponent method has a potential race condition. It modifies the c.components slice without synchronization, which could lead to data races if called concurrently with Close or with other appendComponent calls. While in the current implementation all appendComponent calls happen during initialization before components start, this creates a fragile design. Consider adding mutex protection or documenting that this method must only be called during initialization.