Skip to content

Commit 166b1bc

Browse files
committed
test(cutline): retry an MCP request once when its reused socket was reset
fetch keeps an idle socket for 4 s and the server closes it after 5 s. When a synchronous test step blocks the process long enough, both timers fire together and the reused socket is reset before the request is read, which made "the tool answers prepare, status and cancel" fail under full-suite load. Only ECONNRESET / UND_ERR_SOCKET is retried, once.
1 parent 008f1e0 commit 166b1bc

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

‎plugins/klarkxy/cutline/tests/helpers.mjs‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,23 @@ export async function getJson(base, pathname) {
145145
*/
146146
export async function mcpRaw(base, body, options = {}) {
147147
const method = options.method ?? 'POST';
148-
const response = await fetch(`${base}/mcp/cutline`, {
148+
const send = () => fetch(`${base}/mcp/cutline`, {
149149
method,
150150
headers: { 'content-type': 'application/json', ...(options.headers ?? {}) },
151151
body: method === 'POST' ? JSON.stringify(body) : undefined,
152152
});
153+
/* fetch keeps an idle socket for 4 s and the server closes it after 5 s.
154+
When a synchronous test step blocks this process long enough, both timers
155+
fire together and the reused socket is reset before the request is read.
156+
A reset is the only failure retried, once, on a fresh socket. */
157+
let response;
158+
try {
159+
response = await send();
160+
} catch (err) {
161+
const code = /** @type {any} */ (err)?.cause?.code;
162+
if (code !== 'ECONNRESET' && code !== 'UND_ERR_SOCKET') throw err;
163+
response = await send();
164+
}
153165
const text = await response.text();
154166
let json = null;
155167
try {

0 commit comments

Comments
 (0)