fix(browser-transfer): abort sibling part workers on the first failure (Q-6.1-5)
A failing range worker only set firstFailure, which the other workers read on their next loop. An in-flight sibling kept retrying its part until its own attempt deadline, so the caller got the failure minutes late. The workers now share a transfer-scoped abort combined with the request signal; the first failure aborts it, and a sibling's resulting ABORTED never replaces the failure that won. Verified: new RED test "aborts in-flight sibling workers as soon as one part fails" (sibling signal was never aborted before the fix) + all gates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
b3a68f70ca
commit
e83cda6f7f
@@ -811,6 +811,22 @@ async function transferMissingParts<Capability>(
|
||||
);
|
||||
let nextIndex = 0;
|
||||
let firstFailure: BrowserDataResult<never> | null = null;
|
||||
// Q-6.1-5. The first failure aborts every sibling worker at once, so an
|
||||
// in-flight part does not keep retrying until its own attempt deadline.
|
||||
// The sibling's resulting ABORTED never replaces the failure that won.
|
||||
const failFast = new AbortController();
|
||||
const transferScope = combineAbortSignals(
|
||||
request.signal,
|
||||
failFast.signal,
|
||||
);
|
||||
const transferRequest = Object.freeze({
|
||||
...request,
|
||||
signal: transferScope.signal,
|
||||
});
|
||||
const fail = (failure: BrowserDataResult<never>): void => {
|
||||
firstFailure ??= failure;
|
||||
failFast.abort();
|
||||
};
|
||||
// R-1.3. The resolved policy already fits maxConcurrency parts in
|
||||
// maxInFlightBytes, so the concurrency createSession requested is real.
|
||||
const workerCount = Math.min(
|
||||
@@ -831,15 +847,15 @@ async function transferMissingParts<Capability>(
|
||||
>,
|
||||
part,
|
||||
crypto: dependencies.crypto,
|
||||
signal: request.signal,
|
||||
signal: transferRequest.signal,
|
||||
});
|
||||
if (!bytes.ok) {
|
||||
firstFailure = bytes;
|
||||
fail(bytes);
|
||||
return;
|
||||
}
|
||||
const uploaded = await uploadPartWithRetry(
|
||||
dependencies,
|
||||
request,
|
||||
transferRequest,
|
||||
manifest,
|
||||
checkpoint,
|
||||
part,
|
||||
@@ -852,17 +868,21 @@ async function transferMissingParts<Capability>(
|
||||
part.byteLength,
|
||||
);
|
||||
if (!uploaded.ok) {
|
||||
firstFailure = uploaded;
|
||||
fail(uploaded);
|
||||
return;
|
||||
}
|
||||
const persisted = await persistReceipt(uploaded.value);
|
||||
if (!persisted.ok) {
|
||||
firstFailure = persisted;
|
||||
fail(persisted);
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
await Promise.all(workers);
|
||||
try {
|
||||
await Promise.all(workers);
|
||||
} finally {
|
||||
transferScope.release();
|
||||
}
|
||||
if (firstFailure) return firstFailure;
|
||||
} else {
|
||||
for await (const partResult of iterateUploadParts({
|
||||
|
||||
Reference in New Issue
Block a user