Our pool of hidden <audio> elements died after a waveform seek because three bugs compounded. Re-seeking every element in one tick queued requests behind Chrome's six-connections-per-host HTTP/1.1 limit. Our stall watchdog read those queued requests as stalled and aborted them with .load(). And a retry budget that never reset on success marked elements permanently exhausted.
The fix was a strict readiness gate, a serialized convergence walk with a generation counter, a watchdog that needs evidence of zero network progress before reloading, and a retry budget that counts consecutive failures. Below are the symptoms, the old code, and the code we shipped.
What did the failure look like?
On a music collaboration platform where artists A/B mastering and mixing revisions, clicking a version tab after any waveform seek did nothing. The tab went active and the header updated, but no audio played. A page reload was the only way out. In DevTools we saw several 206 Partial Content requests to the same object, each one cut off after a few hundred bytes by the next.
The product requirement drove the design. Switching versions has to be gapless, because a gap while toggling ruins the comparison. A gap after a seek is fine. So every version gets its own hidden <audio preload="metadata"> element, kept paused near the playhead and buffering a small range-request window, and a switch is just pause-old, play-new.
That works until you seek. Typical tracks had 3 versions and the real maximum was 7–8. After a seek, every one of those elements needs new bytes from the same origin, all at the same moment.
Why does re-seeking every audio element at once hit Chrome's connection limit?
Each currentTime assignment on a media element aborts its in-flight range request and opens a new one. Over HTTP/1.1, Chrome allows only six connections per host, so seeking seven or eight elements against one object-storage origin in a single tick means the extra requests don't fail. They wait in a queue with no bytes arriving, and our player treated waiting as failure.
This was the drift-correction code that caused the stampede. It ran on every timeupdate of the primary element:
// BEFORE: runs on every primary timeupdate
function syncPoolToPrimary() {
var primaryTime = audio.currentTime;
Object.keys(versionPool).forEach(function (versionNumber) {
var entry = versionPool[versionNumber];
if (!entry || entry.audioEl === audio) return;
if (Math.abs(entry.audioEl.currentTime - primaryTime) > 1.5) {
try {
entry.audioEl.currentTime = primaryTime; // a real seek = a new range request
} catch (e) {}
}
});
}
audio.addEventListener("timeupdate", syncPoolToPrimary);
During normal playback this is harmless, because elements drift past 1.5s one at a time. A user seek moves the primary's currentTime directly, so on the next tick every background element is more than 1.5s out at once, and they all get re-seeked in the same synchronous pass. The limit is documented in Chromium's tracker as a cap of 6 connections per group. It is an HTTP/1.1 behaviour. If your media origin negotiates HTTP/2, the requests multiplex over one connection instead, so check the Protocol column before you assume this is your bug.
Why would a stall watchdog abort a request that is only queued?
The media element fires stalled when it has received no data for about three seconds. A queued request gets no data, so it looks exactly like a dead one. Our watchdog armed a 4-second grace timer on stalled/waiting and then reloaded anything with readyState < 2. A request still waiting for a connection slot fails that check every time.
The WHATWG media element spec says stalled fires after an "implementation-defined length of time, which should be about three seconds" with no data. It says nothing about why no data arrived. Our old watchdog condition, in its essentials:
// BEFORE: grace-timer callback
state.graceTimer = setTimeout(function () {
if (!state.pending) return;
state.pending = false;
if (el.readyState < 2 && !el.paused) recover(); // queued looks identical to dead
}, effectiveGraceMs);
recover() re-assigns src and calls .load(). Per MDN's HTMLMediaElement.load() reference, that aborts the current fetch and starts a new one. So the request goes back to the end of the same queue that caused the delay. The reload triggers another stalled, which triggers another reload, until the retry cap runs out and the element is flagged poolExhausted.
Why did one exhausted element break every tab click?
The instant-switch function returned true whenever a pool entry existed, healthy or not. Its caller used that return value to decide whether to fall back to a slower fetch-and-swap path. So clicking a tab whose element was exhausted or not yet buffered was treated as a successful switch: the dead element became primary and the working fallback never ran.
// BEFORE
function switchToPooledVersion(tabEl) {
var versionNumber = tabEl.getAttribute("data-version-number");
var entry = versionPool[versionNumber];
if (!entry) return false;
var target = entry.audioEl;
if (target === audio) return true;
var wasPlaying = !audio.paused && !audio.ended;
audio.pause();
try { target.currentTime = audio.currentTime; } catch (e) {}
audio = target; // promotes a dead element
if (wasPlaying) audio.play().catch(function () {});
applyVersionData(entry.data, versionNumber);
return true; // caller: if (switchToPooledVersion(tab)) return;
}
A second problem sat in that function too. The last currentTime assignment is a real seek even when the value barely changes. On an element that was otherwise ready, it could still cause the audible hiccup the pool exists to prevent.
Why did the retry budget run out on elements that had already recovered?
The watchdog allowed 3 reloads per element in a rolling 3-minute window, but it only removed timestamps by age and never cleared them after a successful reload. So it was counting all failures in the window, not consecutive ones. Three hiccups that each recovered cleanly used up the budget, and the next minor stall exhausted the element. Worse, there was no way back out.
Once exhausted, recover() returned before starting a reload. The loadedmetadata handler that would have cleared the flag was attached to that reload, so it never ran. We fixed this later than the stampede, while moving playback from raw masters to AAC renditions transcoded at upload. Streaming payload across the catalogue fell from 226 MB to 40 MB. That made seek-and-converge cycles fast enough to hit the 3-in-3-minutes ceiling in ordinary use.
Fix 1: what does a strict gapless-readiness gate check?
An element counts as gapless-ready only if four things are true: readyState is at least HAVE_FUTURE_DATA (3), there is no .error, it isn't flagged exhausted, and its buffered ranges cover the live playhead. The last check is the important one. After a big seek, readyState can stay high from data buffered at the old position.
var GAPLESS_READY_TOLERANCE_SECONDS = 0.2;
function isPoolElementGaplessReady(el, atTime, toleranceSeconds) {
if (!el) return false;
if (el.error) return false; // stale readyState can survive an error
if (el.readyState < 3 /* HAVE_FUTURE_DATA */) return false;
var state = getStallState(el);
if (state && state.poolExhausted) return false;
var target = typeof atTime === "number" ? atTime : el.currentTime;
var tol = typeof toleranceSeconds === "number" ? toleranceSeconds : GAPLESS_READY_TOLERANCE_SECONDS;
var ranges = el.buffered;
if (!ranges || !ranges.length) return false;
for (var i = 0; i < ranges.length; i++) {
if (target >= ranges.start(i) - tol && target <= ranges.end(i) + tol) return true;
}
return false;
}
The switch now returns false when the gate fails, so the caller falls through to fetch-and-swap. It also re-seeks only when drift is larger than the gate's own tolerance:
var primaryTimeAtGate = audio.currentTime;
if (!isPoolElementGaplessReady(target, primaryTimeAtGate)) return false; // fall back, don't eat the click
var wasPlaying = !audio.paused && !audio.ended;
audio.pause();
if (Math.abs(target.currentTime - audio.currentTime) > GAPLESS_READY_TOLERANCE_SECONDS) {
try { target.currentTime = audio.currentTime; } catch (e) {}
}
audio = target;
We also had to decide what the UI should do. We could keep every tab clickable and accept a slower fallback switch sometimes, or disable any tab that couldn't switch gaplessly. We chose to disable. The same gate drives aria-disabled and a dimmed state, re-evaluated on canplay, progress, seeked, waiting and emptied. A tab you can click is always instant, and that is the guarantee an A/B comparison tool needs. Tabs going briefly disabled after a big scrub is the cost.
Fix 2: how do you re-seek a pool of audio elements without a stampede?
Serialize it. Wait until the primary's seeked has been followed by 350ms with no further seeks, then re-seek background elements one at a time, nearest tab first. Each step waits for that element's seeked or canplay, or a 4-second timeout. A generation counter lets a new seek cancel an in-flight walk cleanly.
var SEEK_SETTLE_MS = 350;
var POOL_WALK_STEP_TIMEOUT_MS = 4000;
var walkGeneration = 0;
var poolWalkInProgress = false;
var seekSettleTimer = null;
function convergeOnePoolElement(el, targetTime) {
return new Promise(function (resolve) {
try { el.currentTime = targetTime; } catch (e) { resolve(); return; }
var settled = false, timeoutId = null;
function finish() {
if (settled) return;
settled = true;
clearTimeout(timeoutId);
el.removeEventListener("seeked", finish);
el.removeEventListener("canplay", finish);
resolve();
}
el.addEventListener("seeked", finish);
el.addEventListener("canplay", finish);
timeoutId = setTimeout(finish, POOL_WALK_STEP_TIMEOUT_MS); // one bad element can't stall the chain
});
}
function runPoolConvergenceWalk(myGeneration) {
var ordered = orderPoolByTabAdjacency(); // nearest tab to the active one first
poolWalkInProgress = true;
function step(i) {
if (myGeneration !== walkGeneration || i >= ordered.length) {
poolWalkInProgress = false;
return; // superseded by a newer seek, or done
}
var item = ordered[i];
if (item.entry.audioEl === audio) { step(i + 1); return; } // promoted by a tab click mid-walk
var targetTime = audio.currentTime; // re-read: playback kept moving
convergeOnePoolElement(item.entry.audioEl, targetTime).then(function () { step(i + 1); });
}
step(0);
}
function schedulePoolConvergence() {
walkGeneration++; // bump NOW so a running walk stops at its next step
var myGeneration = walkGeneration;
clearTimeout(seekSettleTimer);
seekSettleTimer = setTimeout(function () {
seekSettleTimer = null;
if (myGeneration !== walkGeneration) return;
runPoolConvergenceWalk(myGeneration);
}, SEEK_SETTLE_MS);
updateAllTabReadiness(); // disable stale tabs immediately, not on their next event
}
Normal-playback drift still needs correcting, just not as a burst. A heartbeat on the primary's timeupdate runs at most once every 4 seconds. It re-seeks only the single most-drifted element past 1.5s, and skips its turn while a walk is in progress, so the two never compete for connection slots.
The generation counter is bumped on every seeked, before the debounce. A user scrubbing the waveform fires many seeked events. Bumping early means a walk aimed at a position the user has already left stops at its next step boundary, without anyone needing to cancel a Promise chain from outside.
Fix 3: how do you tell a queued request from a stuck one?
Track evidence of network progress separately from readyState. Record the time of each progress event and the furthest buffered.end() seen. When the grace timer arms, snapshot both. When it fires, reload only if readyState is low and neither signal moved during the grace window. Then reset the retry budget on every successful reload.
el.addEventListener("progress", function () {
state.lastProgressAt = Date.now();
try {
var r = el.buffered;
if (r && r.length) {
var end = r.end(r.length - 1);
if (end > state.lastBufferedEnd) state.lastBufferedEnd = end;
}
} catch (e) {}
});
function armGraceTimer() {
if (state.pending) return;
state.pending = true;
var progressAtArm = state.lastProgressAt;
var bufferedEndAtArm = state.lastBufferedEnd;
state.graceTimer = setTimeout(function () {
state.graceTimer = null;
if (!state.pending) return;
state.pending = false;
if (!(el.readyState < 2 && !el.paused)) return;
var progressHappened = state.lastProgressAt > progressAtArm;
var bufferedGrew = state.lastBufferedEnd > bufferedEndAtArm;
if (progressHappened || bufferedGrew) return; // slow or queued, not dead
recover();
}, effectiveGraceMs);
}
el.addEventListener("stalled", armGraceTimer);
el.addEventListener("waiting", armGraceTimer);
The spec has the browser fire progress roughly every 350ms while bytes are arriving, so a 4-second window with none is meaningful. The grace period also grows by 25% per pool position, up to 6 positions, because elements further back are more likely to be waiting behind their siblings. Inside recover(), the successful-reload handler is what makes the budget count consecutive failures:
el.addEventListener("loadedmetadata", function restoreAfterReload() {
clearTimeout(state.recoveryTimeoutTimer);
state.recovering = false; // re-entrancy guard: one reload in flight per element
state.retryTimestamps = []; // CONSECUTIVE failures, not cumulative
state.poolExhausted = false; // exhaustion is no longer terminal
el.currentTime = clamp(capturedTime, 0, el.duration || capturedTime);
if (wasPlaying) el.play().catch(function () {});
}, { once: true });
The state.recovering guard (with a 10-second safety timeout) prevents a separate failure loop. A fresh .load() fires its own stalled/waiting while it re-buffers, and without the guard that would start a second reload on top of the first.
Why did seeking after a version switch stop triggering convergence?
Our first version of the fix bound the seeked listener once, at init, to whichever element was primary at that moment. Because audio is reassigned on every switch, any seek after the first toggle triggered no walk at all. With only the 4-second heartbeat left, a 7–8 version track took about 30 seconds to re-enable every tab.
This is the same kind of bug as the other two. State was tied to one specific element, in a design where which element is primary changes at runtime. The fix was to bind seeked on every element when it is created, with a guard:
// inside bindPoolListeners(el), once per pool element
el.addEventListener("seeked", function () {
if (audio !== this) return; // ignore the walk's own programmatic seeks on background elements
schedulePoolConvergence();
});
The guard matters. Without it, each re-seek the walk performs on a background element fires seeked, bumps the generation and restarts the walk. You get an endless loop of the walk cancelling itself.
How do you confirm you are hitting the per-origin connection cap in 2026?
In Chrome DevTools, open the Network panel and filter to media, then seek. Look for several 206 requests to the same host where the later ones show a long "Stalled" or "Queueing" phase in the Timing tab, and check that the Protocol column reads http/1.1. If requests to the same object keep getting cancelled and re-issued, your own code is aborting them.
- Count concurrent media requests to one host. More than six on HTTP/1.1 means the extra ones are waiting.
- Log a timestamp for every
stalledand every reload. If reloads follow stalls roughly one grace period later, the watchdog is causing the problem. - Log
retryTimestamps.lengthnext to successful reloads. If it never returns to zero, your budget is cumulative. - Check what your switch function returns when the target is broken. If it reports success, a click can promote a dead element.
Serving media over HTTP/2 removes the per-host connection cap. It does not fix the other three bugs. A watchdog that can't tell queued from stuck, a gate that always reports success, and a budget that never resets will still fail under ordinary network jitter. They just fail less often, which makes them harder to find.
What is the complete pattern?
A pool of <audio> elements died after a seek because a burst of re-seeks exceeded Chrome's six-connections-per-host limit, and the stall watchdog aborted the queued requests. An instant-switch function that always reported success turned one exhausted element into a dead toggle, and a cumulative retry budget made exhaustion permanent.
The fix has four parts: gate every instant switch on buffered coverage of the playhead, re-seek the pool one element at a time under a generation counter, reload only when there is zero progress evidence, and count only consecutive failures. All four come from one rule: when the "current" element keeps changing, never tie state to whichever element happened to be primary at setup.