Skip to content

Commit

Permalink
added host file save again after delay to fix #79
Browse files Browse the repository at this point in the history
  • Loading branch information
cjimti committed Sep 4, 2019
1 parent 506f185 commit 1f33e70
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion cmd/kubefwd/services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"path/filepath"
"strconv"
"sync"
"time"

"github.com/txn2/kubefwd/pkg/fwdcfg"
"github.com/txn2/kubefwd/pkg/fwdhost"
Expand Down Expand Up @@ -216,13 +217,24 @@ Try:
ipC = ipC + 1
}
}

log.Printf("Saving hosts file\n")
err = hostFile.Save()
if err != nil {
log.Error("Error saving hosts file", err)
}

// @TODO this needs a better solution
// from here it is not possible to determine if all host entries have
// be written. This race condition was introduced in:
// https://github.com/txn2/kubefwd/pull/76
// Introducing a two second wait-and-save should cover most if
// not all use cases for now.
time.Sleep(2 * time.Second)
err = hostFile.Save()
if err != nil {
log.Error("Error saving hosts file", err)
}

wg.Wait()

log.Printf("Done...\n")
Expand Down

0 comments on commit 1f33e70

Please sign in to comment.