Skip to content

Commit

Permalink
Fixed crash due to concurrent map iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
Forceu committed Jan 11, 2025
1 parent 82e3d9d commit d11a140
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions internal/storage/processingstatus/pstatusdb/PStatusDb.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ func Set(status models.UploadStatus) {
func deleteAllExpiredStatus() {
allStatus := GetAll()
cutOff := time.Now().Add(-24 * time.Hour).Unix()
statusMutex.Lock()
newStatusMap := make(map[string]models.UploadStatus)
for _, status := range allStatus {
if status.Creation < cutOff {
statusMutex.Lock()
delete(statusMap, status.ChunkId)
statusMutex.Unlock()
if status.Creation > cutOff {
newStatusMap[status.ChunkId] = status
}
}
statusMap = newStatusMap
statusMutex.Unlock()
}

func doGarbageCollection(runPeriodically bool) {
Expand Down

0 comments on commit d11a140

Please sign in to comment.