|
1 | 1 | package nginx |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "context" |
4 | 5 | "fmt" |
5 | 6 | "net/http" |
6 | 7 | "os" |
@@ -362,7 +363,7 @@ func (lm *LocalManager) SetPlusClients(plusClient *client.NginxClient, plusConfi |
362 | 363 |
|
363 | 364 | // UpdateServersInPlus updates NGINX Plus servers of the given upstream. |
364 | 365 | func (lm *LocalManager) UpdateServersInPlus(upstream string, servers []string, config ServerConfig) error { |
365 | | - err := verifyConfigVersion(lm.plusConfigVersionCheckClient, lm.configVersion) |
| 366 | + err := verifyConfigVersion(lm.plusConfigVersionCheckClient, lm.configVersion, lm.verifyClient.timeout) |
366 | 367 | if err != nil { |
367 | 368 | return fmt.Errorf("error verifying config version: %w", err) |
368 | 369 | } |
@@ -393,7 +394,7 @@ func (lm *LocalManager) UpdateServersInPlus(upstream string, servers []string, c |
393 | 394 |
|
394 | 395 | // UpdateStreamServersInPlus updates NGINX Plus stream servers of the given upstream. |
395 | 396 | func (lm *LocalManager) UpdateStreamServersInPlus(upstream string, servers []string) error { |
396 | | - err := verifyConfigVersion(lm.plusConfigVersionCheckClient, lm.configVersion) |
| 397 | + err := verifyConfigVersion(lm.plusConfigVersionCheckClient, lm.configVersion, lm.verifyClient.timeout) |
397 | 398 | if err != nil { |
398 | 399 | return fmt.Errorf("error verifying config version: %w", err) |
399 | 400 | } |
@@ -432,8 +433,11 @@ func (lm *LocalManager) CreateOpenTracingTracerConfig(content string) error { |
432 | 433 | // verifyConfigVersion is used to check if the worker process that the API client is connected |
433 | 434 | // to is using the latest version of nginx config. This way we avoid making changes on |
434 | 435 | // a worker processes that is being shut down. |
435 | | -func verifyConfigVersion(httpClient *http.Client, configVersion int) error { |
436 | | - req, err := http.NewRequest("GET", "http://nginx-plus-api/configVersionCheck", nil) |
| 436 | +func verifyConfigVersion(httpClient *http.Client, configVersion int, timeout time.Duration) error { |
| 437 | + ctx := context.Background() |
| 438 | + reqContext, cancel := context.WithTimeout(ctx, timeout) |
| 439 | + defer cancel() |
| 440 | + req, err := http.NewRequestWithContext(reqContext, "GET", "http://nginx-plus-api/configVersionCheck", nil) |
437 | 441 | if err != nil { |
438 | 442 | return fmt.Errorf("error creating request: %w", err) |
439 | 443 | } |
|
0 commit comments