Skip to content

Commit

Permalink
fix dead lock (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
tianxiaoliang authored Sep 17, 2020
1 parent 9cb622d commit 8a9ec41
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 20 deletions.
9 changes: 1 addition & 8 deletions examples/event/event.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
name: Tom Smith
age: 1
#spouse
# name: Jane Smith
# age: 23
children:
name: Jimmy Smith
age: 19
age: 3321111
Binary file removed examples/file/main
Binary file not shown.
4 changes: 2 additions & 2 deletions source/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ func (cli *Source) GetConfigurations() (map[string]interface{}, error) {

//GetConfigurationByKey gets required configuration for matching key
func (cli *Source) GetConfigurationByKey(key string) (interface{}, error) {
cli.Lock()
defer cli.Unlock()
cli.RLock()
defer cli.RUnlock()
value, ok := cli.Configurations[key]
if !ok {
return nil, source.ErrKeyNotExist
Expand Down
4 changes: 2 additions & 2 deletions source/configmap/configmap_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ func (cmSource *configMapSource) GetConfigurations() (map[string]interface{}, er
}

func (cmSource *configMapSource) GetConfigurationByKey(key string) (interface{}, error) {
cmSource.Lock()
defer cmSource.Unlock()
cmSource.RLock()
defer cmSource.RUnlock()

for ckey, confInfo := range cmSource.Configurations {
if confInfo == nil {
Expand Down
4 changes: 2 additions & 2 deletions source/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ func (es *Source) GetConfigurations() (map[string]interface{}, error) {

//GetConfigurationByKey gets required configuration for a particular key
func (es *Source) GetConfigurationByKey(key string) (interface{}, error) {
es.Lock()
defer es.Unlock()
es.RLock()
defer es.RUnlock()
value, ok := es.Configurations[key]
if !ok {
return nil, source.ErrKeyNotExist
Expand Down
5 changes: 3 additions & 2 deletions source/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ func (fSource *Source) GetConfigurations() (map[string]interface{}, error) {

//GetConfigurationByKey get one key value
func (fSource *Source) GetConfigurationByKey(key string) (interface{}, error) {
fSource.Lock()
defer fSource.Unlock()
fSource.RLock()
defer fSource.RUnlock()

for ckey, confInfo := range fSource.Configurations {
if confInfo == nil {
Expand Down Expand Up @@ -433,6 +433,7 @@ func (wth *watch) watchFile() {
openlog.Error("convert error " + err.Error())
continue
}
openlog.Debug(fmt.Sprintf("new config: %v", newConf))
events := wth.fileSource.compareUpdate(newConf, event.Name)
openlog.Debug(fmt.Sprintf("generated events %v", events))
for _, e := range events {
Expand Down
4 changes: 2 additions & 2 deletions source/mem/mem.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func (ms *Source) GetConfigurations() (map[string]interface{}, error) {

//GetConfigurationByKey gets required memory configuration for a particular key
func (ms *Source) GetConfigurationByKey(key string) (interface{}, error) {
ms.Lock()
defer ms.Unlock()
ms.RLock()
defer ms.RUnlock()
value, ok := ms.Configurations[key]
if !ok {
return nil, source.ErrKeyNotExist
Expand Down
4 changes: 2 additions & 2 deletions source/remote/configcenter/config_center_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ func (rs *Source) refreshConfigurations() error {

//GetConfigurationByKey gets required configuration for a particular key
func (rs *Source) GetConfigurationByKey(key string) (interface{}, error) {
rs.Lock()
rs.RLock()
configSrcVal, ok := rs.currentConfig[key]
rs.Unlock()
rs.RUnlock()
if ok {
return configSrcVal, nil
}
Expand Down

0 comments on commit 8a9ec41

Please sign in to comment.