Skip to content

Commit

Permalink
bugfix: error in Do will never return to outer scope
Browse files Browse the repository at this point in the history
former bugfix is not correct, this correct it

pass nil to errChan if no err

format code, directly pass err to errChan

Signed-off-by: Guangming Wang <guangming.wang@daocloud.io>
  • Loading branch information
Guangming Wang committed Sep 28, 2019
1 parent 3a85983 commit 4c065b5
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions internal/olm/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,19 @@ type Manager struct {
}

func (m *Manager) initialize() (err error) {
errChan := make(chan error, 1)
defer close(errChan)
m.once.Do(func() {
if m.Client == nil {
cfg, err := config.GetConfig()
if err != nil {
err = errors.Wrapf(err, "failed to get Kubernetes config")
errChan <- errors.Wrapf(err, "failed to get Kubernetes config")
return
}

client, err := ClientForConfig(cfg)
if err != nil {
err = errors.Wrapf(err, "failed to create manager client")
errChan <- errors.Wrapf(err, "failed to create manager client")
return
}
m.Client = client
Expand All @@ -61,7 +63,9 @@ func (m *Manager) initialize() (err error) {
if m.Timeout <= 0 {
m.Timeout = DefaultTimeout
}
errChan <- nil
})
err = <-errChan
return err
}

Expand Down

0 comments on commit 4c065b5

Please sign in to comment.