mirror of
https://github.com/qdm12/gluetun.git
synced 2026-07-31 01:13:21 +02:00
fix(healthcheck): prevent race condition on the healthchecker (#3400)
Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com> Thanks also to @arturhoo for also trying to resolve this issue in #3410
This commit is contained in:
@@ -45,6 +45,7 @@ type Loop struct {
|
||||
start <-chan struct{}
|
||||
running chan<- models.LoopStatus
|
||||
userTrigger bool
|
||||
healthDone <-chan struct{}
|
||||
// Internal constant values
|
||||
backoffTime time.Duration
|
||||
}
|
||||
@@ -70,6 +71,11 @@ func NewLoop(vpnSettings settings.VPN, ipv6SupportLevel netlink.IPv6SupportLevel
|
||||
statusManager := loopstate.New(constants.Stopped, start, running, stop, stopped)
|
||||
state := state.New(statusManager, vpnSettings)
|
||||
|
||||
// Initialize healthDone channel to a closed channel so that the first time
|
||||
// we call <-l.healthDone it does not block
|
||||
healthDone := make(chan struct{})
|
||||
close(healthDone)
|
||||
|
||||
return &Loop{
|
||||
statusManager: statusManager,
|
||||
state: state,
|
||||
@@ -98,6 +104,7 @@ func NewLoop(vpnSettings settings.VPN, ipv6SupportLevel netlink.IPv6SupportLevel
|
||||
stop: stop,
|
||||
stopped: stopped,
|
||||
userTrigger: true,
|
||||
healthDone: healthDone,
|
||||
backoffTime: defaultBackoffTime,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user