Skip to content
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

fix: processing pickup race condition #5374

Merged
merged 1 commit into from
Dec 17, 2024
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
11 changes: 10 additions & 1 deletion warehouse/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ type Router struct {
inProgressMap map[workerIdentifierMapKey][]jobID
inProgressMapLock sync.RWMutex

processingMu sync.Mutex

scheduledTimesCache map[string][]int
scheduledTimesCacheLock sync.RWMutex

Expand Down Expand Up @@ -371,18 +373,22 @@ loop:
continue
}

r.processingMu.Lock()
inProgressNamespaces := r.getInProgressNamespaces()
r.logger.Debugf(`Current inProgress namespace identifiers for %s: %v`, r.destType, inProgressNamespaces)

uploadJobsToProcess, err := r.uploadsToProcess(ctx, availableWorkers, inProgressNamespaces)
if err != nil && ctx.Err() == nil {
r.logger.Errorn("Error getting uploads to process", logger.NewErrorField(err))
r.processingMu.Unlock()
return err
}

for _, uploadJob := range uploadJobsToProcess {
r.setDestInProgress(uploadJob.warehouse, uploadJob.upload.ID)
}
r.processingMu.Unlock()

for _, uploadJob := range uploadJobsToProcess {
workerName := r.workerIdentifier(uploadJob.warehouse)

r.workerChannelMapLock.RLock()
Expand Down Expand Up @@ -596,6 +602,9 @@ func (r *Router) handlePriorityForWaitingUploads(ctx context.Context, warehouse
return defaultUploadPriority, nil
}

r.processingMu.Lock()
defer r.processingMu.Unlock()

// If it is present do nothing else delete it
if _, inProgress := r.isUploadJobInProgress(warehouse, latestInfo.ID); !inProgress {
if err := r.uploadRepo.DeleteWaiting(ctx, latestInfo.ID); err != nil {
Expand Down
Loading