keep cancelled outline and search asks free during the Nominatim probe

Recheck the caller's signal right after the capability probe on every path, so an ask cleared while the probe is pending starts no outline or last-resort search request, whether the probe says configured, unknown or not configured.
This commit is contained in:
manjunath committed 2026-10-30 23:27:17 +05:30
1 parent f32ab5446b
commit 3824b4ebfc
4 files changed
+69 -7

No files matched your search

+4 -2
View File
@@ -96,8 +96,10 @@ export function createNominatimOutlineClient({
if (remembered.has(key)) return remembered.get(key);
// A cancelled ask spends nothing.
signal?.throwIfAborted();
if (configured && (await configured()) === false) {
signal?.throwIfAborted();
const capability = configured ? await configured() : null;
// The probe may have waited: an ask cancelled meanwhile still spends nothing.
signal?.throwIfAborted();
if (capability === false) {
unavailable = {
unavailable: true,
retryable: false,
+31
View File
@@ -179,3 +179,34 @@ test('a configured server is asked as usual after one probe', async () => {
assert.equal(calls.length, 2);
assert.equal(probes.length, 1);
});
test('an ask cancelled while the capability probe is pending spends nothing', async () => {
for (const [label, answer] of [
['configured', () => reply(200, { configured: true })],
['unknown', () => reply(404, { error: 'Not Found' })],
['unconfigured', () => reply(200, { configured: false })],
]) {
let release;
const held = new Promise((resolve) => {
release = resolve;
});
const { calls, lookup } = client(
() => reply(200, { status: 'ZERO_RESULTS', outline: null }),
{
status: async () => {
await held;
return answer();
},
},
);
const controller = new AbortController();
const pending = lookup(
{ query: 'Paris', kind: 'city' },
{ signal: controller.signal },
);
controller.abort();
release();
await assert.rejects(pending, { name: 'AbortError' }, label);
assert.equal(calls.length, 0, `${label}: no outline request`);
}
});