Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions db-connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -3040,6 +3040,23 @@ func GetOrgStatistics(ctx context.Context, orgId string) (*ExecutionInfo, error)
}
}

if (stats.OrgId != orgId) && (len(orgId) > 0) {
log.Printf("[WARNING] Org stats data corruption detected. Fixing org stats for org %s (was %s)", orgId, stats.OrgId)
stats.OrgId = orgId
Copy link
Member

Choose a reason for hiding this comment

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

If orgId is empty somehow, this causes a recursive failure due to SetOrgStatistics() calling GetOrgStatistics() in that case. Would cause self-DOS.

Why isn't this fix in SetOrgStatistics() instead of in Get()? Makes little sense to me

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We aren't calling setOrgStatistics() to update the stats we are using transaction and updating directly to "org_statistics". Let me add check for the org id length check so, it won't cause any recursive failure issue.

Copy link
Member

Choose a reason for hiding this comment

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

I still think it will, and will call you at 3AM the day it happens 😆

org, err := GetOrg(ctx, orgId)
if err == nil {
stats.OrgName = org.Name
err = SetOrgStatistics(ctx, *stats, orgId)
if err != nil {
log.Printf("[WARNING] Failed fixing org stats for org %s: %s", orgId, err)
} else {
log.Printf("[INFO] Fixed org stats for org %s", orgId)
}
} else {
log.Printf("[WARNING] Failed getting org during org stats fix for org %s: %s", orgId, err)
}
}

for dailyStatIndex, _ := range stats.DailyStatistics {
for additionIndex, _ := range stats.DailyStatistics[dailyStatIndex].Additions {
stats.DailyStatistics[dailyStatIndex].Additions[additionIndex].Date = stats.DailyStatistics[dailyStatIndex].Date
Expand Down
Loading