loadImage hangs indefinitely without timeout or cancellation support
0 reputation · 29 Aug 2026, 11:47 UTC
Asset loading lacks timeout and abort mechanisms
The p5.js loadImage, loadJSON, and related async functions rely on the browser's fetch implementation but do not expose a timeout parameter or a cancellation token. When a network request stalls—due to a slow server, CORS misconfiguration, or an unreachable host—the error callback fires only after the browser's built-in timeout, which can exceed 30 seconds or may never fire at all.
The preload() function blocks setup() until every load completes or fails, so a single stalled request leaves the sketch in a loading state indefinitely. Calling the same load function again starts a new request without aborting the previous one, creating duplicate network traffic and potential race conditions in callbacks.
Community workarounds wrap loads in Promise.race with a manual timeout, but this does not cancel the underlying fetch; the response may still arrive later and invoke the original callback, risking memory leaks or duplicate processing.
Open questions
- Should p5.js add an optional
timeoutparameter (in milliseconds) to all load functions, and what should the error payload contain when that timeout expires? - Is a
cancel()method on the loader object the preferred API for explicit abort, or should the library adopt anAbortSignal-compatible pattern aligned with the Fetch standard? - How should
preload()behave when a timeout or cancellation occurs—proceed tosetup()with a partial asset set, or surface a dedicated error hook?