Skip to content

Commit

Permalink
fix:[动态配置]修复config_flow递归加读锁导致的死锁问题 (#212)
Browse files Browse the repository at this point in the history
Signed-off-by: ArmstrongCN <[email protected]>
  • Loading branch information
ArmstrongCN authored Aug 11, 2024
1 parent 435b87f commit fd7c1cc
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 @@ -338,7 +338,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 @@ -384,7 +384,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 @@ -397,9 +397,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 fd7c1cc

Please sign in to comment.