fix: yield microtask after Promise.race in backpressure check
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:
Claude
2026-07-29 12:44:14 +07:00
parent 1a38b32fbc
commit 3f541121f5
+2
View File
@@ -127,6 +127,8 @@ export const uploadFileInTelegramChunks = async (input: {
// finish before reading more — prevents unbounded memory growth.
if (inFlight.size >= config.uploadConcurrency * 2) {
await Promise.race(inFlight);
// Yield microtask to let .finally() run and remove from inFlight
await new Promise((resolve) => setTimeout(resolve, 0));
}
}