Skip to content

Commit

Permalink
fix:[动态配置]修复config_flow递归加读锁导致的死锁问题
Browse files Browse the repository at this point in the history
Signed-off-by: ArmstrongCN <[email protected]>
  • Loading branch information
ArmstrongCN committed Aug 10, 2024
1 parent 435b87f commit c727820
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 c727820

Please sign in to comment.