Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloud: Fix stack wake-up function #1727

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions internal/resources/cloud/resource_cloud_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,25 +445,37 @@ func waitForStackReadiness(ctx context.Context, timeout time.Duration, stackURL
return diag.FromErr(joinErr)
}
err := retry.RetryContext(ctx, timeout, func() *retry.RetryError {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, healthURL, nil)
// Query the instance URL directly. This makes the stack wake-up if it has been paused.
// The health endpoint is helpful to check that the stack is ready, but it doesn't wake up the stack.
stackReq, err := http.NewRequestWithContext(ctx, http.MethodGet, stackURL, nil)
if err != nil {
return retry.NonRetryableError(err)
}
resp, err := http.DefaultClient.Do(req)
stackResp, err := http.DefaultClient.Do(stackReq)
if err != nil {
return retry.RetryableError(err)
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
defer stackResp.Body.Close()

healthReq, err := http.NewRequestWithContext(ctx, http.MethodGet, healthURL, nil)
if err != nil {
return retry.NonRetryableError(err)
}
healthResp, err := http.DefaultClient.Do(healthReq)
if err != nil {
return retry.RetryableError(err)
}
defer healthResp.Body.Close()
if healthResp.StatusCode != 200 {
buf := new(bytes.Buffer)
body := ""
_, err = buf.ReadFrom(resp.Body)
_, err = buf.ReadFrom(healthResp.Body)
if err != nil {
body = "unable to read response body, error: " + err.Error()
} else {
body = buf.String()
}
return retry.RetryableError(fmt.Errorf("stack was not ready in %s. Status code: %d, Body: %s", timeout, resp.StatusCode, body))
return retry.RetryableError(fmt.Errorf("stack was not ready in %s. Status code: %d, Body: %s", timeout, healthResp.StatusCode, body))
}

return nil
Expand Down
Loading