Skip to content

Using backoff Do instead of WaitNext function to avoid potential panic#5388

Merged
khanhtc1202 merged 2 commits intomasterfrom
using-backoff-do
Dec 4, 2024
Merged

Using backoff Do instead of WaitNext function to avoid potential panic#5388
khanhtc1202 merged 2 commits intomasterfrom
using-backoff-do

Conversation

@khanhtc1202
Copy link
Member

@khanhtc1202 khanhtc1202 commented Dec 3, 2024

What this PR does:

Using backoff.Do in pipedv1 codebase instead of backoff.WaitNext

Why we need it:

In the backoff package, we have two functions that handle retry logic: WaitNext and Do. The main difference between them (aside from the interface) is that WaitNext does not raise an error in case the context is canceled/stopped, while Do does. So if using WaitNext and the returned value are used as a check for further logic, it may cause panic due to no error returned while the value is nil either.

Which issue(s) this PR fixes:

Fixes #

Does this PR introduce a user-facing change?:

  • How are users affected by this change:
  • Is this breaking change:
  • How to migrate (if breaking change):

Signed-off-by: khanhtc1202 <khanhtc1202@gmail.com>
Signed-off-by: khanhtc1202 <khanhtc1202@gmail.com>
handler.Terminate()
finalStatus := s.executeStage(sig, s.deployment.Stages[0])
assert.Equal(t, model.StageStatus_STAGE_RUNNING, finalStatus)
assert.Equal(t, model.StageStatus_STAGE_FAILURE, finalStatus)
Copy link
Member Author

Choose a reason for hiding this comment

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

This test assertion is changed due to the previous version of s.reportStageStatus use WaitNext, which return no error on context cancel, this should be STAGE_FAILURE as mentioned in this change.
ref: https://github.com/pipe-cd/pipecd/blob/master/pkg/app/pipedv1/controller/scheduler.go#L463

handler.Cancel()
finalStatus := s.executeStage(sig, s.deployment.Stages[0])
assert.Equal(t, model.StageStatus_STAGE_CANCELLED, finalStatus)
assert.Equal(t, model.StageStatus_STAGE_FAILURE, finalStatus)
Copy link
Member Author

Choose a reason for hiding this comment

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

@codecov
Copy link

codecov bot commented Dec 3, 2024

Codecov Report

Attention: Patch coverage is 2.11268% with 139 lines in your changes missing coverage. Please review.

Project coverage is 25.88%. Comparing base (4986dd5) to head (d4899d0).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
pkg/app/pipedv1/controller/planner.go 0.00% 47 Missing ⚠️
pkg/app/pipedv1/controller/controller.go 0.00% 34 Missing ⚠️
pkg/app/pipedv1/trigger/deployment.go 0.00% 18 Missing ⚠️
pkg/app/pipedv1/controller/scheduler.go 15.00% 16 Missing and 1 partial ⚠️
pkg/app/pipedv1/trigger/cache.go 0.00% 11 Missing ⚠️
pkg/app/pipedv1/cmd/piped/piped.go 0.00% 10 Missing ⚠️
pkg/app/server/service/pipedservice/service.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5388      +/-   ##
==========================================
+ Coverage   25.87%   25.88%   +0.01%     
==========================================
  Files         447      447              
  Lines       48233    48207      -26     
==========================================
- Hits        12478    12477       -1     
+ Misses      34784    34759      -25     
  Partials      971      971              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@Warashi Warashi left a comment

Choose a reason for hiding this comment

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

LGTM

@ffjlabo
Copy link
Member

ffjlabo commented Dec 4, 2024

📝 For my understanding
backoff.WaitNext handles context canceling inside and returns bool.
https://github.com/pipe-cd/pipecd/blob/master/pkg/backoff/backoff.go#L76-L91

It happened the bug related to the WaitNext before.
#5388

Copy link
Member

@ffjlabo ffjlabo left a comment

Choose a reason for hiding this comment

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

Thank you!

@khanhtc1202 khanhtc1202 merged commit aaf5551 into master Dec 4, 2024
@khanhtc1202 khanhtc1202 deleted the using-backoff-do branch December 4, 2024 07:24
@github-actions github-actions bot mentioned this pull request Jan 21, 2025
@github-actions github-actions bot mentioned this pull request Mar 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants