From d11a140f999611d00dc97bf16e6bfefe9c257faf Mon Sep 17 00:00:00 2001 From: Marc Ole Bulling Date: Sat, 11 Jan 2025 17:18:56 +0100 Subject: [PATCH] Fixed crash due to concurrent map iteration --- .../storage/processingstatus/pstatusdb/PStatusDb.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/internal/storage/processingstatus/pstatusdb/PStatusDb.go b/internal/storage/processingstatus/pstatusdb/PStatusDb.go index 7cece5d..0884427 100644 --- a/internal/storage/processingstatus/pstatusdb/PStatusDb.go +++ b/internal/storage/processingstatus/pstatusdb/PStatusDb.go @@ -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) {