Skip to content

Commit

Permalink
impr(S3UTILS-181): Gracefully handle NoSuchBucket errors to reduce ne…
Browse files Browse the repository at this point in the history
…edless retries
  • Loading branch information
tmacro committed Nov 18, 2024
1 parent 73124f1 commit 78a7a3e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
11 changes: 10 additions & 1 deletion service-level-sidecar/bucketd.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ const params = {

const metadata = new BucketClientInterface(params, bucketclient, rootLogger);

const listObjects = utils.retryable(metadata.listObject.bind(metadata));
const listObjects = utils.retryable((bucket, params, log, cb) => metadata.listObject(bucket, params, log, (err, res) => {
if (err && err.NoSuchBucket) {
return cb(null, []);
}
return cb(err, res);
}));

/**
* List all s3 buckets implemented as a async generator
Expand All @@ -36,6 +41,10 @@ async function* listBuckets(log) {
// eslint-disable-next-line no-await-in-loop
res = await listObjects(usersBucket, { ...listingParams, gt }, log);
} catch (error) {
if (error.NoSuchBucket) {
log.info('no buckets found');
return;
}
log.error('Error during listing', { error });
throw error;
}
Expand Down
12 changes: 7 additions & 5 deletions service-level-sidecar/scuba.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ const params = {

const metadata = new BucketClientInterface(params, bucketclient, rootLogger);

const listObjects = utils.retryable(metadata.listObject.bind(metadata));
const listObjects = utils.retryable((bucket, params, log, cb) => metadata.listObject(bucket, params, log, (err, res) => {
if (err && err.NoSuchBucket) {
return cb(null, []);
}
return cb(err, res);
}));

function roundToDay(timestamp) {
return new Date(
Expand Down Expand Up @@ -53,10 +58,7 @@ async function getMetrics(classType, resourceName, sessionId, timestamp, log) {
value: JSON.parse(value),
};
} catch (error) {
if (error.NoSuchBucket) {
return null;
}
log.error('error during metric listing', { error: error.message });
log.error('error during metric listing', { bucket, error: error.message });
throw error;
}
}
Expand Down

0 comments on commit 78a7a3e

Please sign in to comment.