diff --git a/src/utils/chunked-storage.ts b/src/utils/chunked-storage.ts index 74f5d32..4a6ff57 100644 --- a/src/utils/chunked-storage.ts +++ b/src/utils/chunked-storage.ts @@ -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)); } }