-
Notifications
You must be signed in to change notification settings - Fork 30
fix(webhook): avoid panics #671
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -402,14 +402,6 @@ func PostWebhook(c *gin.Context) { | |
| if err != nil { | ||
| retErr := fmt.Errorf("%s: unable to get pipeline configuration for %s: %w", baseErr, r.GetFullName(), err) | ||
|
|
||
| // check if the retry limit has been exceeded | ||
| if i < retryLimit { | ||
| logrus.WithError(retErr).Warning("retrying") | ||
|
|
||
| // continue to the next iteration of the loop | ||
| continue | ||
| } | ||
|
|
||
|
Comment on lines
-405
to
-412
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. opted to remove this retry logic since ConfigBackoff is already retrying 5x. if that fails it's likely this is just failing, period. |
||
| util.HandleError(c, http.StatusNotFound, retErr) | ||
|
|
||
| h.SetStatus(constants.StatusFailure) | ||
|
|
@@ -427,8 +419,8 @@ func PostWebhook(c *gin.Context) { | |
| retErr := fmt.Errorf("%s: unable to get repo %s: %w", baseErr, r.GetFullName(), err) | ||
|
|
||
| // check if the retry limit has been exceeded | ||
| if i < retryLimit { | ||
| logrus.WithError(retErr).Warning("retrying") | ||
| if i < retryLimit-1 { | ||
| logrus.WithError(retErr).Warningf("retrying #%d", i+1) | ||
|
|
||
| // continue to the next iteration of the loop | ||
| continue | ||
|
|
@@ -499,6 +491,7 @@ func PostWebhook(c *gin.Context) { | |
|
|
||
| return | ||
| } | ||
|
|
||
| // reset the pipeline type for the repo | ||
| // | ||
| // The pipeline type for a repo can change at any time which can break compiling | ||
|
|
@@ -537,8 +530,8 @@ func PostWebhook(c *gin.Context) { | |
| retErr := fmt.Errorf("%s: failed to create pipeline for %s: %w", baseErr, r.GetFullName(), err) | ||
|
|
||
| // check if the retry limit has been exceeded | ||
| if i < retryLimit { | ||
| logrus.WithError(retErr).Warning("retrying") | ||
| if i < retryLimit-1 { | ||
| logrus.WithError(retErr).Warningf("retrying #%d", i+1) | ||
|
|
||
| // continue to the next iteration of the loop | ||
| continue | ||
|
|
@@ -569,13 +562,19 @@ func PostWebhook(c *gin.Context) { | |
| b.SetPipelineID(pipeline.GetID()) | ||
|
|
||
| // create the objects from the pipeline in the database | ||
| // TODO: | ||
| // - if a build gets created and something else fails midway, | ||
| // the next loop will attempt to create the same build, | ||
| // using the same Number and thus create a constraint | ||
| // conflict; consider deleting the partially created | ||
| // build object in the database | ||
| err = planBuild(database.FromContext(c), p, b, r) | ||
| if err != nil { | ||
| retErr := fmt.Errorf("%s: %w", baseErr, err) | ||
|
|
||
| // check if the retry limit has been exceeded | ||
| if i < retryLimit { | ||
| logrus.WithError(retErr).Warning("retrying") | ||
| if i < retryLimit-1 { | ||
| logrus.WithError(retErr).Warningf("retrying #%d", i+1) | ||
|
|
||
| // reset fields set by cleanBuild for retry | ||
| b.SetError("") | ||
|
|
@@ -596,7 +595,7 @@ func PostWebhook(c *gin.Context) { | |
|
|
||
| // break the loop because everything was successful | ||
| break | ||
| } | ||
| } // end of retry loop | ||
|
|
||
| // send API call to update repo for ensuring counter is incremented | ||
| err = database.FromContext(c).UpdateRepo(r) | ||
|
|
@@ -610,6 +609,28 @@ func PostWebhook(c *gin.Context) { | |
| return | ||
| } | ||
|
|
||
| // return error if pipeline didn't get populated | ||
| if p == nil { | ||
| retErr := fmt.Errorf("%s: failed to set pipeline for %s: %w", baseErr, r.GetFullName(), err) | ||
| util.HandleError(c, http.StatusBadRequest, retErr) | ||
|
|
||
| h.SetStatus(constants.StatusFailure) | ||
| h.SetError(retErr.Error()) | ||
|
|
||
| return | ||
| } | ||
|
|
||
| // return error if build didn't get populated | ||
| if b == nil { | ||
| retErr := fmt.Errorf("%s: failed to set build for %s: %w", baseErr, r.GetFullName(), err) | ||
| util.HandleError(c, http.StatusBadRequest, retErr) | ||
|
|
||
| h.SetStatus(constants.StatusFailure) | ||
| h.SetError(retErr.Error()) | ||
|
|
||
| return | ||
| } | ||
|
|
||
| // send API call to capture the triggered build | ||
| b, err = database.FromContext(c).GetBuild(b.GetNumber(), r) | ||
| if err != nil { | ||
|
|
@@ -618,6 +639,8 @@ func PostWebhook(c *gin.Context) { | |
|
|
||
| h.SetStatus(constants.StatusFailure) | ||
| h.SetError(retErr.Error()) | ||
|
|
||
| return | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we probably don't want to return a build if there was an error. this also creates a conflict because this sets a 500 return code that later gets changed to a 200. |
||
| } | ||
|
|
||
| // set the BuildID field | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we don't handle any potential errors here, we will get issues downstream from here