diff --git a/consul/rpc.go b/consul/rpc.go index c0f91cf42..ae3fd6781 100644 --- a/consul/rpc.go +++ b/consul/rpc.go @@ -30,6 +30,15 @@ const ( // maxQueryTime is used to bound the limit of a blocking query maxQueryTime = 600 * time.Second + // defaultQueryTime is the amount of time we block waiting for a change + // if no time is specified. Previously we would wait the maxQueryTime. + defaultQueryTime = 300 * time.Second + + // jitterFraction is a the limit to the amount of jitter we apply + // to a user specified MaxQueryTime. We divide the specified time by + // the fraction. So 16 == 6.25% limit of jitter + jitterFraction = 16 + // Warn if the Raft command is larger than this. // If it's over 1MB something is probably being abusive. raftWarnSize = 1024 * 1024 @@ -332,9 +341,12 @@ func (s *Server) blockingRPCOpt(opts *blockingRPCOptions) error { if opts.queryOpts.MaxQueryTime > maxQueryTime { opts.queryOpts.MaxQueryTime = maxQueryTime } else if opts.queryOpts.MaxQueryTime <= 0 { - opts.queryOpts.MaxQueryTime = maxQueryTime + opts.queryOpts.MaxQueryTime = defaultQueryTime } + // Apply a small amount of jitter to the request + opts.queryOpts.MaxQueryTime += randomStagger(opts.queryOpts.MaxQueryTime / jitterFraction) + // Setup a query timeout timeout = time.NewTimer(opts.queryOpts.MaxQueryTime) diff --git a/website/source/docs/agent/http.html.markdown b/website/source/docs/agent/http.html.markdown index 7ada4d670..9e1ae0b9b 100644 --- a/website/source/docs/agent/http.html.markdown +++ b/website/source/docs/agent/http.html.markdown @@ -39,9 +39,9 @@ query string parameter to the value of `X-Consul-Index`, indicating that the cli to wait for any changes subsequent to that index. In addition to `index`, endpoints that support blocking will also honor a `wait` -parameter specifying a maximum duration for the blocking request. If not set, it will -default to 10 minutes. This value can be specified in the form of "10s" or "5m" (i.e., -10 seconds or 5 minutes, respectively). +parameter specifying a maximum duration for the blocking request. This is limited to +10 minutes. If not set, the wait time defaults to 5 minutes. This value can be specified +in the form of "10s" or "5m" (i.e., 10 seconds or 5 minutes, respectively). A critical note is that the return of a blocking request is **no guarantee** of a change. It is possible that the timeout was reached or that there was an idempotent write that does