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

fix: race condition when updating registry settings #4036

Merged
merged 2 commits into from
Sep 13, 2023
Merged
Changes from 1 commit
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
34 changes: 22 additions & 12 deletions pkg/handlers/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,21 +210,31 @@ func (h *Handler) UpdateAppRegistry(w http.ResponseWriter, r *http.Request) {
return
}

skipImagePush := updateAppRegistryRequest.IsReadOnly
if foundApp.IsAirgap {
// TODO: pushing images not yet supported in airgapped instances.
skipImagePush = true
}

latestSequence, err := store.GetStore().GetLatestAppSequence(foundApp.ID, true)
if err != nil {
logger.Error(errors.Wrapf(err, "failed to get latest app sequence for app %s", foundApp.Slug))
updateAppRegistryResponse.Error = err.Error()
JSON(w, http.StatusInternalServerError, updateAppRegistryResponse)
return
}
Comment on lines +213 to +225
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this bit out of the goroutine since we don't want to set an initial task status of "running" if the query fails.


// set task status before starting the goroutine so that the UI can show the status
if err := store.GetStore().SetTaskStatus("image-rewrite", "Updating registry settings", "running"); err != nil {
logger.Error(errors.Wrap(err, "failed to set task status"))
updateAppRegistryResponse.Error = err.Error()
JSON(w, http.StatusInternalServerError, updateAppRegistryResponse)
return
}

// in a goroutine, start pushing the images to the remote registry
// we will let this function return while this happens
go func() {
skipImagePush := updateAppRegistryRequest.IsReadOnly
if foundApp.IsAirgap {
// TODO: pushing images not yet supported in airgapped instances.
skipImagePush = true
}

latestSequence, err := store.GetStore().GetLatestAppSequence(foundApp.ID, true)
if err != nil {
logger.Error(errors.Wrapf(err, "failed to get latest app sequence for app %s", foundApp.Slug))
return
}

appDir, err := registry.RewriteImages(
foundApp.ID, latestSequence, updateAppRegistryRequest.Hostname,
updateAppRegistryRequest.Username, registryPassword,
Expand Down
Loading