consul: proactively clear timers
This commit is contained in:
parent
2bc43844bc
commit
23a1df1548
|
@ -314,7 +314,7 @@ type blockingRPCOptions struct {
|
||||||
// blockingRPCOpt is the replacement for blockingRPC as it allows
|
// blockingRPCOpt is the replacement for blockingRPC as it allows
|
||||||
// for more parameterization easily. It should be prefered over blockingRPC.
|
// for more parameterization easily. It should be prefered over blockingRPC.
|
||||||
func (s *Server) blockingRPCOpt(opts *blockingRPCOptions) error {
|
func (s *Server) blockingRPCOpt(opts *blockingRPCOptions) error {
|
||||||
var timeout <-chan time.Time
|
var timeout *time.Timer
|
||||||
var notifyCh chan struct{}
|
var notifyCh chan struct{}
|
||||||
var state *StateStore
|
var state *StateStore
|
||||||
|
|
||||||
|
@ -336,7 +336,7 @@ func (s *Server) blockingRPCOpt(opts *blockingRPCOptions) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup a query timeout
|
// Setup a query timeout
|
||||||
timeout = time.After(opts.queryOpts.MaxQueryTime)
|
timeout = time.NewTimer(opts.queryOpts.MaxQueryTime)
|
||||||
|
|
||||||
// Setup the notify channel
|
// Setup the notify channel
|
||||||
notifyCh = make(chan struct{}, 1)
|
notifyCh = make(chan struct{}, 1)
|
||||||
|
@ -344,6 +344,7 @@ func (s *Server) blockingRPCOpt(opts *blockingRPCOptions) error {
|
||||||
// Ensure we tear down any watchers on return
|
// Ensure we tear down any watchers on return
|
||||||
state = s.fsm.State()
|
state = s.fsm.State()
|
||||||
defer func() {
|
defer func() {
|
||||||
|
timeout.Stop()
|
||||||
state.StopWatch(opts.tables, notifyCh)
|
state.StopWatch(opts.tables, notifyCh)
|
||||||
if opts.kvWatch {
|
if opts.kvWatch {
|
||||||
state.StopWatchKV(opts.kvPrefix, notifyCh)
|
state.StopWatchKV(opts.kvPrefix, notifyCh)
|
||||||
|
@ -378,7 +379,7 @@ RUN_QUERY:
|
||||||
select {
|
select {
|
||||||
case <-notifyCh:
|
case <-notifyCh:
|
||||||
goto REGISTER_NOTIFY
|
goto REGISTER_NOTIFY
|
||||||
case <-timeout:
|
case <-timeout.C:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue