Revisit waitgroup (#241)
* Fix Add to waitgroup out of goroutines calling wg.Done() * Pass waitgroup to other loop functions
This commit is contained in:
@@ -14,7 +14,7 @@ import (
|
||||
|
||||
type Looper interface {
|
||||
Run(ctx context.Context, wg *sync.WaitGroup)
|
||||
RunRestartTicker(ctx context.Context)
|
||||
RunRestartTicker(ctx context.Context, wg *sync.WaitGroup)
|
||||
Restart()
|
||||
Start()
|
||||
Stop()
|
||||
@@ -139,7 +139,6 @@ func (l *looper) waitForSubsequentStart(ctx context.Context, unboundCancel conte
|
||||
}
|
||||
|
||||
func (l *looper) Run(ctx context.Context, wg *sync.WaitGroup) {
|
||||
wg.Add(1)
|
||||
defer wg.Done()
|
||||
const fallback = false
|
||||
l.useUnencryptedDNS(fallback)
|
||||
@@ -282,7 +281,8 @@ func (l *looper) useUnencryptedDNS(fallback bool) {
|
||||
l.logger.Error("no ipv4 DNS address found for providers %s", settings.Providers)
|
||||
}
|
||||
|
||||
func (l *looper) RunRestartTicker(ctx context.Context) {
|
||||
func (l *looper) RunRestartTicker(ctx context.Context, wg *sync.WaitGroup) {
|
||||
defer wg.Done()
|
||||
ticker := time.NewTicker(time.Hour)
|
||||
settings := l.GetSettings()
|
||||
if settings.UpdatePeriod > 0 {
|
||||
|
||||
@@ -98,7 +98,6 @@ func (l *looper) SetAllServers(allServers models.AllServers) {
|
||||
}
|
||||
|
||||
func (l *looper) Run(ctx context.Context, wg *sync.WaitGroup) {
|
||||
wg.Add(1)
|
||||
defer wg.Done()
|
||||
select {
|
||||
case <-l.restart:
|
||||
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
)
|
||||
|
||||
type Looper interface {
|
||||
Run(ctx context.Context)
|
||||
RunRestartTicker(ctx context.Context)
|
||||
Run(ctx context.Context, wg *sync.WaitGroup)
|
||||
RunRestartTicker(ctx context.Context, wg *sync.WaitGroup)
|
||||
Restart()
|
||||
Stop()
|
||||
GetPeriod() (period time.Duration)
|
||||
@@ -74,7 +74,8 @@ func (l *looper) logAndWait(ctx context.Context, err error) {
|
||||
<-ctx.Done()
|
||||
}
|
||||
|
||||
func (l *looper) Run(ctx context.Context) {
|
||||
func (l *looper) Run(ctx context.Context, wg *sync.WaitGroup) {
|
||||
defer wg.Done()
|
||||
select {
|
||||
case <-l.restart:
|
||||
case <-ctx.Done():
|
||||
@@ -124,7 +125,8 @@ func (l *looper) Run(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func (l *looper) RunRestartTicker(ctx context.Context) {
|
||||
func (l *looper) RunRestartTicker(ctx context.Context, wg *sync.WaitGroup) {
|
||||
defer wg.Done()
|
||||
ticker := time.NewTicker(time.Hour)
|
||||
period := l.GetPeriod()
|
||||
if period > 0 {
|
||||
|
||||
@@ -42,7 +42,6 @@ func New(address string, logger logging.Logger, restartOpenvpn, restartUnbound,
|
||||
}
|
||||
|
||||
func (s *server) Run(ctx context.Context, wg *sync.WaitGroup) {
|
||||
wg.Add(1)
|
||||
server := http.Server{Addr: s.address, Handler: s.makeHandler()}
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
|
||||
@@ -82,7 +82,6 @@ func (l *looper) setEnabled(enabled bool) {
|
||||
}
|
||||
|
||||
func (l *looper) Run(ctx context.Context, wg *sync.WaitGroup) {
|
||||
wg.Add(1)
|
||||
defer wg.Done()
|
||||
waitForStart := true
|
||||
for waitForStart {
|
||||
|
||||
@@ -89,7 +89,6 @@ func (l *looper) Start() { l.start <- struct{}{} }
|
||||
func (l *looper) Stop() { l.stop <- struct{}{} }
|
||||
|
||||
func (l *looper) Run(ctx context.Context, wg *sync.WaitGroup) {
|
||||
wg.Add(1)
|
||||
defer wg.Done()
|
||||
waitForStart := true
|
||||
for waitForStart {
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
type Looper interface {
|
||||
Run(ctx context.Context, wg *sync.WaitGroup)
|
||||
RunRestartTicker(ctx context.Context)
|
||||
RunRestartTicker(ctx context.Context, wg *sync.WaitGroup)
|
||||
Restart()
|
||||
Stop()
|
||||
GetPeriod() (period time.Duration)
|
||||
@@ -123,7 +123,8 @@ func (l *looper) Run(ctx context.Context, wg *sync.WaitGroup) {
|
||||
}
|
||||
}
|
||||
|
||||
func (l *looper) RunRestartTicker(ctx context.Context) {
|
||||
func (l *looper) RunRestartTicker(ctx context.Context, wg *sync.WaitGroup) {
|
||||
defer wg.Done()
|
||||
ticker := time.NewTicker(time.Hour)
|
||||
period := l.GetPeriod()
|
||||
if period > 0 {
|
||||
|
||||
Reference in New Issue
Block a user