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) }