From a5a9f051cd369c3bc9cd6b4872669e65c13b61c5 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Fri, 12 Dec 2014 19:17:04 -0800 Subject: [PATCH] consul: Ignore zero ttl on session --- command/agent/session_endpoint.go | 7 ++++--- consul/session_endpoint.go | 2 +- consul/state_store.go | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/command/agent/session_endpoint.go b/command/agent/session_endpoint.go index 878a0b5843..25d48634cf 100644 --- a/command/agent/session_endpoint.go +++ b/command/agent/session_endpoint.go @@ -2,11 +2,12 @@ package agent import ( "fmt" - "github.com/hashicorp/consul/consul" - "github.com/hashicorp/consul/consul/structs" "net/http" "strings" "time" + + "github.com/hashicorp/consul/consul" + "github.com/hashicorp/consul/consul/structs" ) const ( @@ -61,7 +62,7 @@ func (s *HTTPServer) SessionCreate(resp http.ResponseWriter, req *http.Request) return nil, nil } - if ttl < structs.SessionTTLMin || ttl > structs.SessionTTLMax { + if ttl != 0 && (ttl < structs.SessionTTLMin || ttl > structs.SessionTTLMax) { resp.WriteHeader(400) resp.Write([]byte(fmt.Sprintf("Request TTL '%s', must be between [%v-%v]", args.Session.TTL, structs.SessionTTLMin, structs.SessionTTLMax))) return nil, nil diff --git a/consul/session_endpoint.go b/consul/session_endpoint.go index 8d7f73ddbf..3d6bfc1c98 100644 --- a/consul/session_endpoint.go +++ b/consul/session_endpoint.go @@ -47,7 +47,7 @@ func (s *Session) Apply(args *structs.SessionRequest, reply *string) error { return fmt.Errorf("Session TTL '%s' invalid: %v", args.Session.TTL, err) } - if ttl < structs.SessionTTLMin || ttl > structs.SessionTTLMax { + if ttl != 0 && (ttl < structs.SessionTTLMin || ttl > structs.SessionTTLMax) { return fmt.Errorf("Invalid Session TTL '%d', must be between [%v=%v]", ttl, structs.SessionTTLMin, structs.SessionTTLMax) } diff --git a/consul/state_store.go b/consul/state_store.go index 4ff6af8c8a..3cd70dbe8c 100644 --- a/consul/state_store.go +++ b/consul/state_store.go @@ -1342,7 +1342,7 @@ func (s *StateStore) SessionCreate(index uint64, session *structs.Session) error return fmt.Errorf("Invalid Session TTL '%s': %v", session.TTL, err) } - if ttl < structs.SessionTTLMin || ttl > structs.SessionTTLMax { + if ttl != 0 && (ttl < structs.SessionTTLMin || ttl > structs.SessionTTLMax) { return fmt.Errorf("Invalid Session TTL '%s', must be between [%v-%v]", session.TTL, structs.SessionTTLMin, structs.SessionTTLMax) }