From bf6427ad2366033a222aecbb0b1d77b4c9871cd1 Mon Sep 17 00:00:00 2001 From: Alexandre Beslic Date: Mon, 25 May 2015 12:36:27 -0700 Subject: [PATCH] Additional check enforcing ttl >= 10s for Consul and ephemeral entries Signed-off-by: Alexandre Beslic --- pkg/store/consul.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/store/consul.go b/pkg/store/consul.go index d0e8e4f729..beb3ec74a3 100644 --- a/pkg/store/consul.go +++ b/pkg/store/consul.go @@ -16,6 +16,10 @@ const ( // watched key has changed. This affects the minimum time it takes to // cancel a watch. DefaultWatchWaitTime = 15 * time.Second + + // MinimumTimeToLive is the minimum TTL value allowed by Consul for + // Ephemeral entries + MinimumTimeToLive = 10 * time.Second ) // Consul embeds the client and watches @@ -81,8 +85,11 @@ func (s *Consul) setTimeout(time time.Duration) { } // SetEphemeralTTL sets the ttl for ephemeral nodes -func (s *Consul) setEphemeralTTL(time time.Duration) { - s.ephemeralTTL = time +func (s *Consul) setEphemeralTTL(ttl time.Duration) { + if ttl < MinimumTimeToLive { + log.Fatal("Consul does not allow a ttl < 10s, please specify a ttl >= 10s") + } + s.ephemeralTTL = ttl } // CreateEphemeralSession creates the a global session