Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion internal/healthcheck/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ func (c *Checker) Start(ctx context.Context) (runError <-chan error, err error)
func (c *Checker) Stop() error {
c.stop()
<-c.done
c.configMutex.Lock()
defer c.configMutex.Unlock()
c.tlsDialAddrs = nil
c.icmpTargetIPs = nil
c.smallCheckType = ""
Expand All @@ -170,6 +172,9 @@ func (c *Checker) smallPeriodicCheck(ctx context.Context) error {
icmpTargetIPs := make([]netip.Addr, len(c.icmpTargetIPs))
copy(icmpTargetIPs, c.icmpTargetIPs)
c.configMutex.Unlock()
if c.smallCheckType != smallCheckDNS && len(icmpTargetIPs) == 0 {
return nil
}
tryTimeouts := []time.Duration{
5 * time.Second,
5 * time.Second,
Expand Down Expand Up @@ -202,11 +207,18 @@ func (c *Checker) smallPeriodicCheck(ctx context.Context) error {
}

func (c *Checker) fullPeriodicCheck(ctx context.Context) error {
c.configMutex.Lock()
tlsDialAddrs := make([]string, len(c.tlsDialAddrs))
copy(tlsDialAddrs, c.tlsDialAddrs)
c.configMutex.Unlock()
if len(tlsDialAddrs) == 0 {
return nil
}
// 20s timeout in case the connection is under stress
// See https://github.com/qdm12/gluetun/issues/2270
tryTimeouts := []time.Duration{10 * time.Second, 15 * time.Second, 30 * time.Second}
check := func(ctx context.Context, try int) error {
tlsDialAddr := c.tlsDialAddrs[try%len(c.tlsDialAddrs)]
tlsDialAddr := tlsDialAddrs[try%len(tlsDialAddrs)]
return tcpTLSCheck(ctx, c.dialer, tlsDialAddr)
}
return withRetries(ctx, tryTimeouts, c.logger, "TCP+TLS dial", check)
Expand Down
14 changes: 14 additions & 0 deletions internal/healthcheck/checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ func Test_Checker_fullcheck(t *testing.T) {
})
}

func Test_Checker_periodicCheckEmptyTargets(t *testing.T) {
t.Parallel()

checker := &Checker{smallCheckType: smallCheckICMP}

err := checker.fullPeriodicCheck(context.Background())

assert.NoError(t, err)

err = checker.smallPeriodicCheck(context.Background())

assert.NoError(t, err)
}

func Test_makeAddressToDial(t *testing.T) {
t.Parallel()

Expand Down