Skip to content

fix(audio): release the loading flag so a failed effect can retry - #13

Merged
KaykCaputo merged 1 commit into
KaykCaputo:masterfrom
bfs2021:fix/audio-loading-retry
Oct 28, 2026
Merged

KaykCaputo merged 1 commit into
KaykCaputo:masterfrom
bfs2021:fix/audio-loading-retry

Conversation

@bfs2021

@bfs2021 bfs2021 commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Problem

Audio effects could get permanently stuck after one failed load: loadEffects() set loading[key] = true but neither the XHR error/timeout/non-success paths nor the decode paths cleared it, so every later unlock() skipped the effect (loading[key] guard) and no new request was ever sent (Fixes #4).

Root cause

The flag had a set site but no settle site. The request lifecycle has four exits — network error, timeout, non-success status, decode failure — and success, and only the success exit was harmless (because the buffers[key] guard short-circuits first).

Fix

Every exit now runs one shared settle callback (passed as decode's done) that deletes loading[key]. The flag stays set for the duration of the request, so parallel calls still skip an in-flight effect instead of duplicating it, and successful decodes keep caching the buffer.

Testing

New tests/audio.test.cjs (node --test, jsdom-free vm harness matching the repo's other .test.cjs files) drives the page's public unlock() flow with a fake XHR and AudioContext: a network error is followed by a new request (fails on the old code), a decoded effect is cached and not re-requested, a decode failure leaves the effect retryable (fails on the old code), and parallel unlocks never duplicate an in-flight request. The full node --test tests/*.test.cjs shows the same 3 pre-existing Windows-environment failures on untouched master and with this change; 12 pass either way.

loadEffects set loading[key] and no path cleared it, so one failed XHR
or decode left the effect permanently skipped. Every exit now settles
the flag through a shared done callback, while it stays set for the
duration of the request so parallel calls still cannot duplicate one.
@KaykCaputo
KaykCaputo merged commit a80bed9 into KaykCaputo:master Oct 28, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Sound effects cannot retry after a loading failure

2 participants