Skip to content

Commit

Permalink
if we failed to load pulbic config, clean up
Browse files Browse the repository at this point in the history
the config will still be updated later by the noded service anyway
  • Loading branch information
muhamadazmy committed Feb 2, 2023
1 parent d678e48 commit a4c9214
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pkg/network/public/persist.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ var ErrNoPublicConfig = errors.New("no public configuration")

// LoadPublicConfig loads public config from file
func LoadPublicConfig() (*pkg.PublicConfig, error) {
file, err := os.Open(getPersistencePath(publicConfigFile))
path := getPersistencePath(publicConfigFile)
file, err := os.Open(path)
if os.IsNotExist(err) {
// it's not an error to not have config
// but we return a nil config
Expand All @@ -53,7 +54,13 @@ func LoadPublicConfig() (*pkg.PublicConfig, error) {
defer file.Close()
var cfg pkg.PublicConfig
if err := json.NewDecoder(file).Decode(&cfg); err != nil {
return nil, errors.Wrap(err, "failed to decode public config")
// if we failed to load the file for any reason, it's okay
// we can ignore it then will be reset by the node service
// will avoid the node getting stuck on start
// the only draw back is that public config will take a little bit more
// time to apply.
_ = os.RemoveAll(path)
return nil, ErrNoPublicConfig
}

return &cfg, nil
Expand Down

0 comments on commit a4c9214

Please sign in to comment.