{"record":{"id":"0f1488f94d205679","repo":"apify/crawlee","slug":"requestlist-sources-are-already-loading-or-were-lo","errorCode":null,"errorMessage":"RequestList sources are already loading or were loaded.","messagePattern":"RequestList sources are already loading or were loaded\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/storages/request_list.ts","lineNumber":360,"sourceCode":"        this.#keepDuplicateUrls = keepDuplicateUrls;\n\n        // Will be empty after initialization to save memory.\n        this.#sources = sources ? [...sources] : [];\n        this.#sourcesFunction = sourcesFunction;\n\n        // The proxy configuration used for `requestsFromUrl` requests.\n        this.#proxyConfiguration = proxyConfiguration;\n\n        this.persistState = this.persistState.bind(this);\n    }\n\n    /**\n     * Loads all remote sources of URLs and potentially starts periodic state persistence.\n     * This function must be called before you can start using the instance in a meaningful way.\n     */\n    private async initialize(): Promise<this> {\n        if (this.#isLoading) {\n            throw new Error('RequestList sources are already loading or were loaded.');\n        }\n\n        this.#isLoading = true;\n        await purgeDefaultStorages({ onlyPurgeOnce: true });\n\n        const [state, persistedRequests] = await this.loadStateAndPersistedRequests();\n\n        // Add persisted requests / new sources in a memory efficient way because with very\n        // large lists, we were running out of memory.\n        if (persistedRequests) {\n            await this.addPersistedRequests(persistedRequests as Buffer);\n        } else {\n            await this.addRequestsFromSources();\n        }\n\n        this.restoreState(state as RequestListState);\n        this.#isInitialized = true;\n        if (this.#persistRequestsKey && !this.areRequestsPersisted) await this.persistRequests();","sourceCodeStart":342,"sourceCodeEnd":378,"githubUrl":"https://github.com/apify/crawlee/blob/dbe57fb09ca607ad59dcf998f3925ef9ac3bb26c/packages/core/src/storages/request_list.ts#L342-L378","documentation":"initialize() loads remote sources and starts persistence; running it twice on the same RequestList would duplicate requests and corrupt state. A guard flag (#isLoading) makes a second call throw this error.","triggerScenarios":"Calling list.initialize() twice; RequestList.open() called twice for the same list while an earlier initialization is in-flight or completed internally; manual initialize after open() (open() already initializes).","commonSituations":"Calling RequestList.open() and then also list.initialize() in legacy migrated code; retry/failed-run wrappers that re-open the list without checking; concurrent open() calls from multiple code paths.","solutions":["Call RequestList.open() only — it initializes internally; remove manual initialize() calls","Cache the returned instance and reuse it instead of re-opening/re-initializing","Use a memoized promise for open() if it may be invoked concurrently from several places"],"exampleFix":"// before\nconst list = await RequestList.open('list', opts);\nawait list.initialize(); // throws\n// after\nconst list = await RequestList.open('list', opts); // already initialized","handlingStrategy":"validation","validationCode":"const listCache = new Map();\nasync function openListOnce(name, options) {\n  if (!listCache.has(name)) listCache.set(name, RequestList.open(name, options));\n  return listCache.get(name);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await list.initialize();\n} catch (e) {\n  if (e.message.includes('already loading or were loaded')) {\n    // safe to ignore: list is ready or initialization is in progress\n  } else throw e;\n}","preventionTips":["Rely on RequestList.open() — never call initialize() manually","Memoize open() promises to prevent concurrent double-open","Reuse a single list instance across your crawler setup"],"tags":["request-list","lifecycle","double-initialization"],"backgroundTag":"double-initialization","analyzedSha":"dbe57fb09ca607ad59dcf998f3925ef9ac3bb26c","analyzedAt":"2026-08-30T22:22:28.328Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}