diff --git a/services/config.go b/services/config.go index e7bfbf907..be47b2fee 100644 --- a/services/config.go +++ b/services/config.go @@ -177,8 +177,10 @@ func (cs *configService) fetch() (*apipb.ConfigResponse, int64, error) { resp *http.Response sleep int64 ) + ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute) + defer cancel() for { - req, err := cs.newRequest() + req, err := cs.newRequest(ctx) if err != nil { return nil, 0, err } @@ -226,7 +228,7 @@ func (cs *configService) fetch() (*apipb.ConfigResponse, int64, error) { // newRequest returns a new ConfigRequest with the current client info, proxy ids, and the last // time the config was fetched. -func (cs *configService) newRequest() (*http.Request, error) { +func (cs *configService) newRequest(ctx context.Context) (*http.Request, error) { conf := cs.configHandler.GetConfig() proxies := []*apipb.ProxyConnectConfig{} if conf != nil { // not the first request @@ -251,7 +253,6 @@ func (cs *configService) newRequest() (*http.Request, error) { return nil, fmt.Errorf("unable to marshal config request: %w", err) } - ctx, _ := context.WithTimeout(context.Background(), 30*time.Second) req, err := http.NewRequestWithContext(ctx, http.MethodPost, cs.opts.OriginURL, bytes.NewReader(buf)) if err != nil { return nil, fmt.Errorf("unable to create request")