fix: cancel in-progress deploy when webhook triggers new deploy (closes #38) #52
No reviewers
Labels
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: sneak/upaas#52
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch ":fix/deploy-race-condition-38"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Fixes the race condition between manual and webhook deploys (issue #38).
When a webhook-triggered deploy starts for an app that already has a deploy in progress, the existing deploy is now cancelled via context cancellation before the new deploy begins.
Changes
internal/service/deploy/deploy.go: Replace simple mutex-only locking with active deploy tracking (cancel func + done channel per app).Deploy()now acceptscancelExisting boolparameter. AddedcancelActiveDeploy()andcheckCancelled()helpers.internal/service/webhook/webhook.go: PasscancelExisting: truewhen triggering deploys from webhooks.internal/handlers/app.go: PasscancelExisting: falsefor manual deploys (preserves existing ErrDeploymentInProgress behavior).internal/models/deployment.go: AddDeploymentStatusCancelledstatus.How it works
Deploy()registers a cancellable context and done channel inactiveDeploysmapDeploy(ctx, app, eventID, true), it first callscancelActiveDeploy()which cancels the in-progress deploy's context and blocks until it finishescancelledstatus, and returnsErrDeployCancelled✅ Test Results
All tests pass:
✅ Lint Results
No new lint issues. Only pre-existing
testpackageissue ontail_validation_test.go.