Skip to content

refactor: replace legacy WaitNext retry loops with thread-safe backoff.Do closures#6916

Closed
Parthtiw710 wants to merge 1 commit into
pipe-cd:masterfrom
Parthtiw710:refactor/waitnext-to-do
Closed

refactor: replace legacy WaitNext retry loops with thread-safe backoff.Do closures#6916
Parthtiw710 wants to merge 1 commit into
pipe-cd:masterfrom
Parthtiw710:refactor/waitnext-to-do

Conversation

@Parthtiw710

Copy link
Copy Markdown

PR Description

Description

This PR addresses the technical debt of legacy WaitNext() retry loops in the piped application, resolving the project-wide TODO in pkg/backoff/backoff.go:

// TODO: Find all using of WaitNext and replace by Do to avoid panic.

By migrating all manual WaitNext iterations to pipedservice.NewRetry(N).Do closures, we encapsulate retry states, prevent potential data races/concurrency panics, and standardize error propagation.

Changes

1. Trigger Package (pkg/app/piped/trigger/)

  • cache.go: Refactored getLastTriggeredDeployment using backoff.Do and standard pipedservice.NewRetriableErr wrapping. Added type assertion back to the expected *model.ApplicationDeploymentReference return.
  • deployment.go: Updated reportMostRecentlyTriggeredDeployment to run inside a safe .Do() closure.

2. Controller Package (pkg/app/piped/controller/)

  • controller.go: Migrated getMostRecentlySuccessfulDeployment, cancelDeployment, and reportApplicationDeployingStatus to the safe .Do() pattern.
  • planner.go:
    • Refactored reportDeploymentPlanned, reportDeploymentFailed, and reportDeploymentCancelled to use .Do().
    • Fixed a bug in reportDeploymentFailed where ReportDeploymentPlanned was incorrectly called instead of ReportDeploymentCompleted during failure reporting.
  • scheduler.go: Migrated reportStageStatus, reportDeploymentStatusChanged, reportDeploymentCompleted, and reportMostRecentlySuccessfulDeployment.

3. Command Package (pkg/app/piped/cmd/piped/)

  • piped.go: Refactored sendPipedMeta to use .Do(). Kept the local retry variable to preserve calling telemetry (retry.Calls()) inside warning logs.

4. Platform Provider / Lambda (pkg/app/piped/platformprovider/lambda/ & pkg/app/piped/executor/lambda/)

  • client.go: Updated updateFunctionConfiguration to use .Do() loop instead of WaitNext.
  • lambda.go: Refactored the build stage publish step to run within a .Do() closure.

Verification & Testing

All packages compile cleanly under Go 1.25.0 and all unit tests passed successfully:

go test -v ./pkg/app/piped/controller/...
go test -v ./pkg/app/piped/platformprovider/lambda/...
go test -v ./pkg/app/piped/executor/lambda/...
go test -v ./pkg/app/piped/trigger/...

No remaining WaitNext references exist anywhere in pkg/app/piped:

$ grep -rn "WaitNext" pkg/app/piped/
# No results found

@Parthtiw710 Parthtiw710 requested a review from a team as a code owner June 16, 2026 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant