fix(recent-imagery): settle synchronous cancellation

This commit is contained in:
brandonabyrd authored and Byrd-IT committed 2026-11-13 17:12:47 -06:00
1 parent eeda6d51d1
commit 7b76525528
2 files changed
+34 -7

No files matched your search

@@ -23,6 +23,28 @@ async function until(condition, tries = 200, gapMs = 5) {
* alpha, so a draped confirmed-empty half is a black rectangle on the map.
*/
test('synchronous abort inside an abort-ignoring fetch settles immediately', async () => {
const controller = new AbortController();
const source = createRecentImagerySource({
thumbnailUrl: () => 'https://example.invalid/',
halfDeadlineMs: 10000,
fetchImpl: () => {
controller.abort();
return new Promise(() => {});
},
});
const outcome = await Promise.race([
source
.getThumbnail(FIJI_CANDIDATE, FIJI_BOX, { signal: controller.signal })
.then(
() => 'resolved',
(error) => error.name,
),
new Promise((resolve) => setTimeout(() => resolve('stalled'), 50)),
]);
assert.equal(outcome, 'AbortError');
});
// Fiji across the antimeridian: east side (-180 … -177) is the wider half.
const FIJI_BOX = { west: 179, south: -18, east: -177, north: -17 };
const FIJI_DAY = '2026-11-04';
+12 -7
View File
@@ -81,21 +81,26 @@ function probeHalf(
signal?.addEventListener('abort', () => stop(signal.reason), {
once: true,
});
let promise;
try {
promise = fetchImpl(url, { signal: controller.signal });
} catch (error) {
finishTimeout();
throw error;
}
const response = new Promise((resolve, reject) => {
settle = { resolve, reject };
if (controller.signal.aborted) {
reject(controller.signal.reason);
return;
}
if (deadlineMs > 0)
timer = setTimeoutImpl(
() =>
stop(new DOMException('Thumbnail half timed out', 'TimeoutError')),
deadlineMs,
);
let promise;
try {
promise = Promise.resolve(fetchImpl(url, { signal: controller.signal }));
} catch (error) {
finishTimeout();
reject(error);
return;
}
promise.then(
(value) => {
transportSettled = true;