Skip to content

Commit

Permalink
Fix listObjects delay
Browse files Browse the repository at this point in the history
listObjects caused the cache restore to take a minimum of 10 seconds
because the timeout was not cleared when the Promise is resolved or
rejected.
  • Loading branch information
welteki authored and jackieli-tes committed Feb 20, 2024
1 parent f914804 commit cba095d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
10 changes: 6 additions & 4 deletions dist/restore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102862,21 +102862,23 @@ function listObjects(mc, bucket, prefix) {
const h = mc.listObjectsV2(bucket, prefix, true);
const r = [];
let resolved = false;
const timeout = setTimeout(() => {
if (!resolved)
reject(new Error("list objects no result after 10 seconds"));
}, 10000);
h.on("data", (obj) => {
r.push(obj);
});
h.on("error", (e) => {
resolved = true;
reject(e);
clearTimeout(timeout);
});
h.on("end", () => {
resolved = true;
resolve(r);
clearTimeout(timeout);
});
setTimeout(() => {
if (!resolved)
reject(new Error("list objects no result after 10 seconds"));
}, 10000);
});
}
exports.listObjects = listObjects;
Expand Down
10 changes: 6 additions & 4 deletions dist/save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102789,21 +102789,23 @@ function listObjects(mc, bucket, prefix) {
const h = mc.listObjectsV2(bucket, prefix, true);
const r = [];
let resolved = false;
const timeout = setTimeout(() => {
if (!resolved)
reject(new Error("list objects no result after 10 seconds"));
}, 10000);
h.on("data", (obj) => {
r.push(obj);
});
h.on("error", (e) => {
resolved = true;
reject(e);
clearTimeout(timeout);
});
h.on("end", () => {
resolved = true;
resolve(r);
clearTimeout(timeout);
});
setTimeout(() => {
if (!resolved)
reject(new Error("list objects no result after 10 seconds"));
}, 10000);
});
}
exports.listObjects = listObjects;
Expand Down
10 changes: 6 additions & 4 deletions dist/saveOnly/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102789,21 +102789,23 @@ function listObjects(mc, bucket, prefix) {
const h = mc.listObjectsV2(bucket, prefix, true);
const r = [];
let resolved = false;
const timeout = setTimeout(() => {
if (!resolved)
reject(new Error("list objects no result after 10 seconds"));
}, 10000);
h.on("data", (obj) => {
r.push(obj);
});
h.on("error", (e) => {
resolved = true;
reject(e);
clearTimeout(timeout);
});
h.on("end", () => {
resolved = true;
resolve(r);
clearTimeout(timeout);
});
setTimeout(() => {
if (!resolved)
reject(new Error("list objects no result after 10 seconds"));
}, 10000);
});
}
exports.listObjects = listObjects;
Expand Down
11 changes: 7 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,21 +149,24 @@ export function listObjects(
const h = mc.listObjectsV2(bucket, prefix, true);
const r: minio.BucketItem[] = [];
let resolved = false;
const timeout = setTimeout(() => {
if (!resolved)
reject(new Error("list objects no result after 10 seconds"));
}, 10000);

h.on("data", (obj) => {
r.push(obj);
});
h.on("error", (e) => {
resolved = true;
reject(e);
clearTimeout(timeout)
});
h.on("end", () => {
resolved = true;
resolve(r);
clearTimeout(timeout)
});
setTimeout(() => {
if (!resolved)
reject(new Error("list objects no result after 10 seconds"));
}, 10000);
});
}

Expand Down

0 comments on commit cba095d

Please sign in to comment.