Skip to content

Commit

Permalink
fix:[动态配置]修复config_flow递归加读锁导致的死锁问题 (#212) (#215)
Browse files Browse the repository at this point in the history
Signed-off-by: ArmstrongCN <[email protected]>
  • Loading branch information
ArmstrongCN authored Aug 17, 2024
1 parent 1f7b1e7 commit d27bee2
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pkg/flow/configuration/config_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func (c *ConfigFileFlow) mainLoop(ctx context.Context) {
changedConfigFile.GetFileName())

newNotifiedVersion := changedConfigFile.GetVersion()
oldNotifiedVersion := c.getConfigFileNotifiedVersion(cacheKey)
oldNotifiedVersion := c.getConfigFileNotifiedVersion(cacheKey, true)

maxVersion := oldNotifiedVersion
if newNotifiedVersion > oldNotifiedVersion {
Expand Down Expand Up @@ -382,7 +382,7 @@ func (c *ConfigFileFlow) assembleWatchConfigFiles() []*configconnector.ConfigFil
Namespace: configFileMetadata.GetNamespace(),
FileGroup: configFileMetadata.GetFileGroup(),
FileName: configFileMetadata.GetFileName(),
Version: c.getConfigFileNotifiedVersion(cacheKey),
Version: c.getConfigFileNotifiedVersion(cacheKey, false),
})
}

Expand All @@ -395,9 +395,11 @@ func (c *ConfigFileFlow) updateNotifiedVersion(cacheKey string, version uint64)
c.notifiedVersion[cacheKey] = version
}

func (c *ConfigFileFlow) getConfigFileNotifiedVersion(cacheKey string) uint64 {
c.fclock.RLock()
defer c.fclock.RUnlock()
func (c *ConfigFileFlow) getConfigFileNotifiedVersion(cacheKey string, locking bool) uint64 {
if locking {
c.fclock.RLock()
defer c.fclock.RUnlock()
}
version, ok := c.notifiedVersion[cacheKey]
if !ok {
version = initVersion
Expand Down

0 comments on commit d27bee2

Please sign in to comment.