fix: yield microtask after Promise.race in backpressure check
Deploy FileDrop / deploy (push) Successful in 48s
Deploy FileDrop / deploy (push) Successful in 48s
Adds a setTimeout(0) microtask yield after Promise.race to ensure the .finally() handler that removes promises from the inFlight set has executed before the next backpressure check. Also ensure parts array is sorted by partNumber after concurrent uploads complete, since promises resolve in arbitrary order. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -127,6 +127,8 @@ export const uploadFileInTelegramChunks = async (input: {
|
|||||||
// finish before reading more — prevents unbounded memory growth.
|
// finish before reading more — prevents unbounded memory growth.
|
||||||
if (inFlight.size >= config.uploadConcurrency * 2) {
|
if (inFlight.size >= config.uploadConcurrency * 2) {
|
||||||
await Promise.race(inFlight);
|
await Promise.race(inFlight);
|
||||||
|
// Yield microtask to let .finally() run and remove from inFlight
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user