Skip to content

Commit dff1d9b

Browse files
committed
NVSHAS-8116 fixed an issue that could cause incorrect report pruning.
1 parent dd02397 commit dff1d9b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

server/server.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ func scan(w http.ResponseWriter, req *http.Request) {
184184
}
185185
scanRequest.Authorization = req.Header.Get("Authorization")
186186

187-
log.WithFields(log.Fields{"auth": scanRequest.Authorization, "registry": scanRequest.Registry, "artifact": scanRequest.Artifact}).Debug("Scan request received")
188187
//Add to resultmap with wait http code
189188
w.WriteHeader(http.StatusAccepted)
190189

@@ -193,13 +192,15 @@ func scan(w http.ResponseWriter, req *http.Request) {
193192
scanId := ScanRequestReturn{ID: fmt.Sprintf("%v", workloadID.GetNoLock())}
194193
scanRequest.WorkloadID = scanId.ID
195194
scanRequestQueue.Enqueue(scanRequest)
195+
log.WithFields(log.Fields{"workloadid": scanId, "auth": scanRequest.Authorization, "registry": scanRequest.Registry, "artifact": scanRequest.Artifact}).Debug("Scan request received")
196196
workloadID.Increment()
197197
scanRequestQueue.Unlock()
198198
workloadID.Unlock()
199199

200200
reportCache.Lock()
201201
expirationTime := generateExpirationTime()
202-
reportCache.ScanReports[scanId.ID] = ScanReport{Status: http.StatusFound, ExpirationTime: expirationTime}
202+
ScanReport := ScanReport{Status: http.StatusFound, ExpirationTime: expirationTime}
203+
reportCache.ScanReports[scanId.ID] = ScanReport
203204
reportCache.Unlock()
204205

205206
err = json.NewEncoder(w).Encode(scanId)
@@ -350,7 +351,7 @@ func pruneOldEntries() {
350351
for key, value := range reportCache.ScanReports {
351352
if value.ExpirationTime.Before(time.Now()) {
352353
delete(reportCache.ScanReports, key)
353-
log.WithFields(log.Fields{"key": key, "expires": value.ExpirationTime, "now": time.Now()}).Debug("Deleted entry due to expiration time")
354+
log.WithFields(log.Fields{"workloadid": key, "expires": value.ExpirationTime, "now": time.Now()}).Debug("Deleted entry due to expiration time")
354355
}
355356
}
356357
reportCache.Unlock()
@@ -404,6 +405,7 @@ func scanResult(w http.ResponseWriter, req *http.Request) {
404405
}
405406
} else {
406407
w.Header().Add("Location", req.URL.String())
408+
log.WithFields(log.Fields{"id": id}).Debug("Entry not found for scan report")
407409
w.WriteHeader(http.StatusNotFound)
408410
}
409411
reportCache.Unlock()

0 commit comments

Comments
 (0)