fix: serialize interval waits so uploads stagger correctly

Previously all jobs read the same lastStartTime simultaneously,
causing them all to start at once. Now uses a per-hoster promise
chain to ensure each job waits its turn.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Administrator 2026-03-11 03:56:04 +01:00
parent e6bad780ee
commit 1af7f8a94d

View File

@ -35,6 +35,7 @@ class UploadManager extends EventEmitter {
this.cancelledJobIds = new Set();
this.sessionBytes = 0;
this.lastStartTime = {}; // hoster -> timestamp of last upload start
this.intervalLocks = {}; // hoster -> Promise chain for serialized interval waits
this.globalThrottle = null;
}
@ -544,7 +545,10 @@ class UploadManager extends EventEmitter {
});
}
async _waitForInterval(hoster, intervalMs, signal) {
_waitForInterval(hoster, intervalMs, signal) {
// Serialize interval waits per hoster so concurrent jobs queue up properly
const prev = this.intervalLocks[hoster] || Promise.resolve();
const next = prev.then(async () => {
const now = Date.now();
const last = this.lastStartTime[hoster] || 0;
const elapsed = now - last;
@ -552,6 +556,9 @@ class UploadManager extends EventEmitter {
await this._sleep(intervalMs - elapsed, signal);
}
this.lastStartTime[hoster] = Date.now();
});
this.intervalLocks[hoster] = next.catch(() => {});
return next;
}
cancelJobs(jobIds) {