@@ -349,15 +349,17 @@ func (ac *AccessControlHandlersCollection) cachePlaybackAccessControlInfo(playba
349349}
350350
351351func (g * GateClient ) QueryGate (body []byte ) (bool , GateConfig , error ) {
352-
353352 gateConfig := GateConfig {
354353 MaxAge : 0 ,
355354 StaleWhileRevalidate : 0 ,
356355 RateLimit : 0 ,
357356 RefreshInterval : 0 ,
358357 }
359358
360- req , err := http .NewRequest ("POST" , g .gateURL , bytes .NewReader (body ))
359+ ctx , cancel := context .WithTimeout (context .Background (), 2 * time .Second )
360+ defer cancel ()
361+
362+ req , err := http .NewRequestWithContext (ctx , "POST" , g .gateURL , bytes .NewReader (body ))
361363 if err != nil {
362364 return false , gateConfig , err
363365 }
@@ -366,10 +368,18 @@ func (g *GateClient) QueryGate(body []byte) (bool, GateConfig, error) {
366368
367369 res , err := g .Client .Do (req )
368370 if err != nil {
371+ // If the timeout is exceeded, simulate a 2XX status code with 2 minute cache expiration
372+ if err == context .DeadlineExceeded {
373+ glog .Infof ("queryGate timeout exceeded. Setting default cache expiration to 2 minutes." )
374+ gateConfig .MaxAge = 120
375+ gateConfig .StaleWhileRevalidate = 600
376+ gateConfig .RefreshInterval = 60
377+ return true , gateConfig , nil
378+ }
369379 return false , gateConfig , err
370380 }
371-
372381 defer res .Body .Close ()
382+
373383 cc , err := cacheobject .ParseResponseCacheControl (res .Header .Get ("Cache-Control" ))
374384 if err != nil {
375385 return false , gateConfig , err
0 commit comments