Skip to content

Commit

Permalink
only start goroutines on successful setup
Browse files Browse the repository at this point in the history
  • Loading branch information
ironcladlou committed Nov 14, 2019
1 parent 4a4f5ab commit 51160ba
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions pkg/cmd/infra/router/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,20 @@ func makeTLSConfig() (*tls.Config, error) {
return nil, err
}

// Safely reload the certificate as requested.
// Reload when the files change or when the fixed timer fires
ticker := time.NewTicker(5 * time.Minute)
watcher, err := fsnotify.NewWatcher()
if err != nil {
return nil, err
}
if err := watcher.Add(certFile); err != nil {
return nil, err
}
if err := watcher.Add(keyFile); err != nil {
return nil, err
}

// Safely reload the certificate when signaled.
var lock sync.Mutex
reload := make(chan bool) // value will be false for an unscheduled reload
go func() {
Expand All @@ -609,18 +622,7 @@ func makeTLSConfig() (*tls.Config, error) {
}
}()

// Reload when the files change or when the fixed timer fires
ticker := time.NewTicker(5 * time.Minute)
watcher, err := fsnotify.NewWatcher()
if err != nil {
return nil, err
}
if err := watcher.Add(certFile); err != nil {
return nil, err
}
if err := watcher.Add(keyFile); err != nil {
return nil, err
}
// Watch events and trigger reloads.
go func() {
for {
select {
Expand Down

0 comments on commit 51160ba

Please sign in to comment.