fix: avoid cli gateway close race
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
- macOS menu: device list now uses `node.list` (devices only; no agent/tool presence entries).
|
- macOS menu: device list now uses `node.list` (devices only; no agent/tool presence entries).
|
||||||
- macOS menu: device list now shows connected nodes only.
|
- macOS menu: device list now shows connected nodes only.
|
||||||
- iOS node: fix ReplayKit screen recording crash caused by queue isolation assertions during capture.
|
- iOS node: fix ReplayKit screen recording crash caused by queue isolation assertions during capture.
|
||||||
|
- CLI: avoid spurious gateway close errors after successful request/response cycles.
|
||||||
|
|
||||||
## 2.0.0-beta4 — 2025-12-27
|
## 2.0.0-beta4 — 2025-12-27
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ export async function callGateway<T = unknown>(
|
|||||||
const timeoutMs = opts.timeoutMs ?? 10_000;
|
const timeoutMs = opts.timeoutMs ?? 10_000;
|
||||||
return await new Promise<T>((resolve, reject) => {
|
return await new Promise<T>((resolve, reject) => {
|
||||||
let settled = false;
|
let settled = false;
|
||||||
|
let ignoreClose = false;
|
||||||
const stop = (err?: Error, value?: T) => {
|
const stop = (err?: Error, value?: T) => {
|
||||||
if (settled) return;
|
if (settled) return;
|
||||||
settled = true;
|
settled = true;
|
||||||
@@ -49,19 +50,23 @@ export async function callGateway<T = unknown>(
|
|||||||
const result = await client.request<T>(opts.method, opts.params, {
|
const result = await client.request<T>(opts.method, opts.params, {
|
||||||
expectFinal: opts.expectFinal,
|
expectFinal: opts.expectFinal,
|
||||||
});
|
});
|
||||||
client.stop();
|
ignoreClose = true;
|
||||||
stop(undefined, result);
|
stop(undefined, result);
|
||||||
|
client.stop();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
ignoreClose = true;
|
||||||
client.stop();
|
client.stop();
|
||||||
stop(err as Error);
|
stop(err as Error);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onClose: (code, reason) => {
|
onClose: (code, reason) => {
|
||||||
|
if (settled || ignoreClose) return;
|
||||||
stop(new Error(`gateway closed (${code}): ${reason}`));
|
stop(new Error(`gateway closed (${code}): ${reason}`));
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
|
ignoreClose = true;
|
||||||
client.stop();
|
client.stop();
|
||||||
stop(new Error("gateway timeout"));
|
stop(new Error("gateway timeout"));
|
||||||
}, timeoutMs);
|
}, timeoutMs);
|
||||||
|
|||||||
Reference in New Issue
Block a user