Skip to content

Commit b4b9e0b

Browse files
committed
fix: check image cache before skipping sending scan results
The workload cache expires in one minute, which means that images that weren't scanned quickly enough were accidentally not transmitted to Snyk. The check now ensures that it skips sending data only if both the workload and the image are missing.
1 parent 5e7d403 commit b4b9e0b

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/scanner/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ import {
1818
Telemetry,
1919
} from '../transmitter/types';
2020
import { IPullableImage, IScanImage } from './images/types';
21-
import { getWorkloadAlreadyScanned } from '../state';
21+
import {
22+
getWorkloadAlreadyScanned,
23+
getWorkloadImageAlreadyScanned,
24+
} from '../state';
2225

2326
export async function processWorkload(
2427
workloadMetadata: IWorkload[],
@@ -131,8 +134,12 @@ async function scanImagesAndSendResults(
131134

132135
// All workloads are identical, pick the first one
133136
const workload = workloadMetadata[0];
134-
const state = await getWorkloadAlreadyScanned(workload);
135-
if (state === undefined) {
137+
const workloadState = await getWorkloadAlreadyScanned(workload);
138+
const imageState = await getWorkloadImageAlreadyScanned(
139+
workload,
140+
workload.imageId,
141+
);
142+
if (workloadState === undefined && imageState === undefined) {
136143
logger.info(
137144
{ workloadName },
138145
'the workload has been deleted while scanning was in progress, skipping sending scan results',

src/state.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as LruCache from 'lru-cache';
33

44
import { config } from './common/config';
55

6-
const imagesLruCacheOptions = {
6+
const imagesLruCacheOptions: LruCache.Options<string, string> = {
77
// limit cache size so we don't exceed memory limit
88
max: config.IMAGES_SCANNED_CACHE.MAX_SIZE,
99
// limit cache life so if our backend loses track of an image's data,
@@ -12,7 +12,7 @@ const imagesLruCacheOptions = {
1212
updateAgeOnGet: false,
1313
};
1414

15-
const workloadsLruCacheOptions = {
15+
const workloadsLruCacheOptions: LruCache.Options<string, string> = {
1616
// limit cache size so we don't exceed memory limit
1717
max: config.WORKLOADS_SCANNED_CACHE.MAX_SIZE,
1818
// limit cache life so if our backend loses track of an image's data,

0 commit comments

Comments
 (0)