Skip to content

Commit d1e8931

Browse files
Merge pull request #144 from yashsinghcodes/urgent-fix
added constraints for infinite for loop
2 parents 62162fe + 8c29702 commit d1e8931

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

db-connector.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6254,12 +6254,22 @@ func GetPrioritizedApps(ctx context.Context, user User) ([]WorkflowApp, error) {
62546254
if user.ActiveOrg.Id != "" {
62556255
query := datastore.NewQuery(nameKey).Filter("reference_org =", user.ActiveOrg.Id).Limit(queryLimit)
62566256
//log.Printf("[INFO] Before ref org search. Org: %s\n\n", user.ActiveOrg.Id)
6257+
maxAmount := 100
6258+
cnt := 0
62576259
for {
62586260
it := project.Dbclient.Run(ctx, query)
6261+
if cnt > maxAmount {
6262+
log.Printf("[ERROR] Maximum try excided for workflowapp (1)")
6263+
}
62596264

62606265
for {
62616266
innerApp := WorkflowApp{}
62626267
_, err := it.Next(&innerApp)
6268+
cnt += 1
6269+
if cnt > maxAmount {
6270+
log.Printf("[ERROR] Maximum try excided for workfloapp (2)")
6271+
}
6272+
62636273
if err != nil {
62646274
if strings.Contains(fmt.Sprintf("%s", err), "cannot load field") {
62656275
//log.Printf("[ERROR] Error in reference_org app load of %s (%s): %s.", innerApp.Name, innerApp.ID, err)
@@ -11045,16 +11055,28 @@ func GetAllWorkflowExecutionsV2(ctx context.Context, workflowId string, amount i
1104511055
// Create a timeout to prevent the query from taking more than 5 seconds total
1104611056

1104711057
cursorStr := ""
11058+
maxAmount := 100
11059+
cnt := 0
1104811060
for {
1104911061
it := project.Dbclient.Run(ctx, query)
11062+
if cnt > maxAmount {
11063+
log.Printf("[ERROR] Error getting workflow execution (4): reached maximum retries")
11064+
break
11065+
}
1105011066

1105111067
breakOuter := false
1105211068
for {
1105311069
innerWorkflow := WorkflowExecution{}
1105411070
_, err := it.Next(&innerWorkflow)
11071+
if cnt > maxAmount {
11072+
log.Printf("[ERROR] Error getting workflow execution (3): reached maximum retries")
11073+
break
11074+
}
11075+
1105511076
if err != nil {
1105611077
if strings.Contains(err.Error(), "context deadline exceeded") {
1105711078
log.Printf("[WARNING] Error getting workflow executions (1): %s", err)
11079+
cnt += 1
1105811080
breakOuter = true
1105911081
} else {
1106011082
if strings.Contains(err.Error(), `cannot load field`) {

0 commit comments

Comments
 (0)