fix(msteams): clear pending upload timeout on removal (#32555)

thanks @PinoHouse
This commit is contained in:
LawrenceLuo 2026-04-01 22:46:24 +08:00 committed by GitHub
parent cfe4b720a4
commit 83149ed046
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 1 deletions

View File

@ -18,6 +18,7 @@ export interface PendingUpload {
}
const pendingUploads = new Map<string, PendingUpload>();
const pendingTimeouts = new Map<string, ReturnType<typeof setTimeout>>();
/** TTL for pending uploads: 5 minutes */
const PENDING_UPLOAD_TTL_MS = 5 * 60 * 1000;
@ -36,9 +37,11 @@ export function storePendingUpload(upload: Omit<PendingUpload, "id" | "createdAt
pendingUploads.set(id, entry);
// Auto-cleanup after TTL
setTimeout(() => {
const timeout = setTimeout(() => {
pendingUploads.delete(id);
pendingTimeouts.delete(id);
}, PENDING_UPLOAD_TTL_MS);
pendingTimeouts.set(id, timeout);
return id;
}
@ -70,6 +73,11 @@ export function getPendingUpload(id?: string): PendingUpload | undefined {
*/
export function removePendingUpload(id?: string): void {
if (id) {
const timeout = pendingTimeouts.get(id);
if (timeout) {
clearTimeout(timeout);
pendingTimeouts.delete(id);
}
pendingUploads.delete(id);
}
}
@ -85,5 +93,9 @@ export function getPendingUploadCount(): number {
* Clear all pending uploads (for testing).
*/
export function clearPendingUploads(): void {
for (const timeout of pendingTimeouts.values()) {
clearTimeout(timeout);
}
pendingTimeouts.clear();
pendingUploads.clear();
}