Skip to content

Commit

Permalink
Merge pull request hashicorp#19 from hashicorp/bugfix/7
Browse files Browse the repository at this point in the history
Define sync channels without creating and closing them
  • Loading branch information
Rebecca Zanzig authored Oct 19, 2018
2 parents deafd3e + 88ddf64 commit 25f084a
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions subcommand/sync-catalog/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ func (c *Command) Run(args []string) int {
ctx, cancelF := context.WithCancel(context.Background())

// Start the K8S-to-Consul syncer
toConsulCh := make(chan struct{})
close(toConsulCh)
var toConsulCh chan struct{}
if c.flagToConsul {
// Build the Consul sync and start it
syncer := &catalogFromK8S.ConsulSyncer{
Expand Down Expand Up @@ -149,8 +148,7 @@ func (c *Command) Run(args []string) int {
}

// Start Consul-to-K8S sync
toK8SCh := make(chan struct{})
close(toK8SCh)
var toK8SCh chan struct{}
if c.flagToK8S {
sink := &catalogFromConsul.K8SSink{
Client: clientset,
Expand Down Expand Up @@ -187,20 +185,28 @@ func (c *Command) Run(args []string) int {
// Unexpected exit
case <-toConsulCh:
cancelF()
<-toK8SCh
if toK8SCh != nil {
<-toK8SCh
}
return 1

// Unexpected exit
case <-toK8SCh:
cancelF()
<-toConsulCh
if toConsulCh != nil {
<-toConsulCh
}
return 1

// Interrupted, gracefully exit
case <-sigCh:
cancelF()
<-toConsulCh
<-toK8SCh
if toConsulCh != nil {
<-toConsulCh
}
if toK8SCh != nil {
<-toK8SCh
}
return 0
}
}
Expand Down

0 comments on commit 25f084a

Please sign in to comment.