@@ -89,6 +89,10 @@ type ClusterChecker struct {
8989 endPollonProxyCh chan error
9090
9191 pollonMutex sync.Mutex
92+
93+ proxyCheckInterval time.Duration
94+ proxyTimeout time.Duration
95+ configMutex sync.Mutex
9296}
9397
9498func NewClusterChecker (uid string , cfg config ) (* ClusterChecker , error ) {
@@ -104,6 +108,9 @@ func NewClusterChecker(uid string, cfg config) (*ClusterChecker, error) {
104108 stopListening : cfg .stopListening ,
105109 e : e ,
106110 endPollonProxyCh : make (chan error ),
111+
112+ proxyCheckInterval : cluster .DefaultProxyCheckInterval ,
113+ proxyTimeout : cluster .DefaultProxyTimeout ,
107114 }, nil
108115}
109116
@@ -164,15 +171,16 @@ func (c *ClusterChecker) sendPollonConfData(confData pollon.ConfData) {
164171 }
165172}
166173
167- func (c * ClusterChecker ) SetProxyInfo (e store.Store , generation int64 , ttl time.Duration ) error {
174+ func (c * ClusterChecker ) SetProxyInfo (e store.Store , generation int64 , proxyTimeout time.Duration ) error {
168175 proxyInfo := & cluster.ProxyInfo {
169- InfoUID : common .UID (),
170- UID : c .uid ,
171- Generation : generation ,
176+ InfoUID : common .UID (),
177+ UID : c .uid ,
178+ Generation : generation ,
179+ ProxyTimeout : proxyTimeout ,
172180 }
173181 log .Debugf ("proxyInfo dump: %s" , spew .Sdump (proxyInfo ))
174182
175- if err := c .e .SetProxyInfo (context .TODO (), proxyInfo , ttl ); err != nil {
183+ if err := c .e .SetProxyInfo (context .TODO (), proxyInfo , 2 * proxyTimeout ); err != nil {
176184 return err
177185 }
178186 return nil
@@ -205,13 +213,31 @@ func (c *ClusterChecker) Check() error {
205213 return fmt .Errorf ("clusterdata validation failed: %v" , err )
206214 }
207215
216+ cdProxyCheckInterval := cd .Cluster .DefSpec ().ProxyCheckInterval .Duration
217+ cdProxyTimeout := cd .Cluster .DefSpec ().ProxyTimeout .Duration
218+
219+ // use the greater between the current proxy timeout and the one defined in the cluster spec if they're different.
220+ // in this way we're updating our proxyInfo using a timeout that is greater or equal the current active timeout timer.
221+ c .configMutex .Lock ()
222+ proxyTimeout := c .proxyTimeout
223+ if cdProxyTimeout > proxyTimeout {
224+ proxyTimeout = cdProxyTimeout
225+ }
226+ c .configMutex .Unlock ()
227+
208228 proxy := cd .Proxy
209229 if proxy == nil {
210230 log .Infow ("no proxy object available, closing connections to master" )
211231 c .sendPollonConfData (pollon.ConfData {DestAddr : nil })
212232 // ignore errors on setting proxy info
213- if err = c .SetProxyInfo (c .e , cluster .NoGeneration , 2 * cluster . DefaultProxyTimeoutInterval ); err != nil {
233+ if err = c .SetProxyInfo (c .e , cluster .NoGeneration , proxyTimeout ); err != nil {
214234 log .Errorw ("failed to update proxyInfo" , zap .Error (err ))
235+ } else {
236+ // update proxyCheckinterval and proxyTimeout only if we successfully updated our proxy info
237+ c .configMutex .Lock ()
238+ c .proxyCheckInterval = cdProxyCheckInterval
239+ c .proxyTimeout = cdProxyTimeout
240+ c .configMutex .Unlock ()
215241 }
216242 return nil
217243 }
@@ -221,8 +247,14 @@ func (c *ClusterChecker) Check() error {
221247 log .Infow ("no db object available, closing connections to master" , "db" , proxy .Spec .MasterDBUID )
222248 c .sendPollonConfData (pollon.ConfData {DestAddr : nil })
223249 // ignore errors on setting proxy info
224- if err = c .SetProxyInfo (c .e , proxy .Generation , 2 * cluster . DefaultProxyTimeoutInterval ); err != nil {
250+ if err = c .SetProxyInfo (c .e , proxy .Generation , proxyTimeout ); err != nil {
225251 log .Errorw ("failed to update proxyInfo" , zap .Error (err ))
252+ } else {
253+ // update proxyCheckinterval and proxyTimeout only if we successfully updated our proxy info
254+ c .configMutex .Lock ()
255+ c .proxyCheckInterval = cdProxyCheckInterval
256+ c .proxyTimeout = cdProxyTimeout
257+ c .configMutex .Unlock ()
226258 }
227259 return nil
228260 }
@@ -234,12 +266,18 @@ func (c *ClusterChecker) Check() error {
234266 return nil
235267 }
236268 log .Infow ("master address" , "address" , addr )
237- if err = c .SetProxyInfo (c .e , proxy .Generation , 2 * cluster . DefaultProxyTimeoutInterval ); err != nil {
269+ if err = c .SetProxyInfo (c .e , proxy .Generation , proxyTimeout ); err != nil {
238270 // if we failed to update our proxy info when a master is defined we
239271 // cannot ignore this error since the sentinel won't know that we exist
240272 // and are sending connections to a master so, when electing a new
241273 // master, it'll not wait for us to close connections to the old one.
242274 return fmt .Errorf ("failed to update proxyInfo: %v" , err )
275+ } else {
276+ // update proxyCheckinterval and proxyTimeout only if we successfully updated our proxy info
277+ c .configMutex .Lock ()
278+ c .proxyCheckInterval = cdProxyCheckInterval
279+ c .proxyTimeout = cdProxyTimeout
280+ c .configMutex .Unlock ()
243281 }
244282
245283 // start proxing only if we are inside enabledProxies, this ensures that the
@@ -256,7 +294,9 @@ func (c *ClusterChecker) Check() error {
256294}
257295
258296func (c * ClusterChecker ) TimeoutChecker (checkOkCh chan struct {}) {
259- timeoutTimer := time .NewTimer (cluster .DefaultProxyTimeoutInterval )
297+ c .configMutex .Lock ()
298+ timeoutTimer := time .NewTimer (c .proxyTimeout )
299+ c .configMutex .Unlock ()
260300
261301 for {
262302 select {
@@ -275,7 +315,10 @@ func (c *ClusterChecker) TimeoutChecker(checkOkCh chan struct{}) {
275315
276316 // ignore if stop succeeded or not due to timer already expired
277317 timeoutTimer .Stop ()
278- timeoutTimer = time .NewTimer (cluster .DefaultProxyTimeoutInterval )
318+
319+ c .configMutex .Lock ()
320+ timeoutTimer = time .NewTimer (c .proxyTimeout )
321+ c .configMutex .Unlock ()
279322 }
280323 }
281324}
@@ -305,7 +348,10 @@ func (c *ClusterChecker) Start() error {
305348 // report that check was ok
306349 checkOkCh <- struct {}{}
307350 }
308- timerCh = time .NewTimer (cluster .DefaultProxyCheckInterval ).C
351+ c .configMutex .Lock ()
352+ timerCh = time .NewTimer (c .proxyCheckInterval ).C
353+ c .configMutex .Unlock ()
354+
309355 case err := <- c .endPollonProxyCh :
310356 if err != nil {
311357 return fmt .Errorf ("proxy error: %v" , err )
0 commit comments