{"record":{"id":"d9b8f71524c39ed7","repo":"mozilla/pdf.js","slug":"worker-was-destroyed-d9b8f7","errorCode":null,"errorMessage":"Worker was destroyed.","messagePattern":"Worker was destroyed\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/display/api.js","lineNumber":2914,"sourceCode":"        case \"Pattern\":\n          pageProxy.objs.resolve(id, imageData);\n          break;\n        default:\n          throw new Error(`Got unknown object type ${type}`);\n      }\n    });\n\n    messageHandler.on(\"DocProgress\", data => {\n      if (this.destroyed) {\n        return; // Ignore any pending requests if the worker was terminated.\n      }\n      this.#onProgress(data);\n    });\n\n    if (typeof PDFJSDev === \"undefined\" || !PDFJSDev.test(\"MOZCENTRAL\")) {\n      messageHandler.on(\"FetchBinaryData\", async data => {\n        if (this.destroyed) {\n          throw new Error(\"Worker was destroyed.\");\n        }\n        if (!this.binaryDataFactory) {\n          throw new Error(\n            \"`BinaryDataFactory` not initialized, see the `useWorkerFetch` parameter.\"\n          );\n        }\n        return this.binaryDataFactory.fetch(data);\n      });\n    }\n  }\n\n  getData() {\n    return this.messageHandler.sendWithPromise(\"GetData\", null);\n  }\n\n  saveDocument() {\n    if (this.annotationStorage.size <= 0) {\n      warn(","sourceCodeStart":2896,"sourceCodeEnd":2932,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/display/api.js#L2896-L2932","documentation":"A generic Error inside the WorkerTransport's FetchBinaryData message handler: the worker asked the main thread to fetch binary data (image/font stream) but the transport has already been destroyed (this.destroyed). The handler refuses to fulfill the request because the document is gone. This is a non-MOZCENTRAL code path.","triggerScenarios":"The worker emits a FetchBinaryData request after doc/loadingTask.destroy() began; rapid destroy while lazy image/font fetching is still in flight; range-loaded documents where the worker requests data after teardown.","commonSituations":"Closing a document tab/page while background image decoding is active; aggressive cleanup in viewers; memory-pressure driven destroys.","solutions":["Treat this as a benign late-arrival error after destroy; the document is already closing.","Avoid issuing new page/render requests while a destroy is pending.","Await loadingTask.destroy() before releasing references, so late worker messages have a settled transport."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Suppress late binary-fetch requests once teardown has started.\nif (doc && !doc.destroyed) {\n  await page.getTextContent();\n}","typeGuard":null,"tryCatchPattern":"// The error surfaces on the worker side; ensure await loadingTask.destroy()\n// completes before releasing refs so late messages have a settled transport.\ntry {\n  await doc.destroy();\n} catch (e) {\n  if (/Worker was destroyed/.test(e.message)) return;\n  throw e;\n}","preventionTips":["Await loadingTask.destroy() so the transport settles before you release it.","Stop issuing page/render requests once destroy begins.","Treat late 'Worker was destroyed.' errors after close as benign."],"tags":["worker","lifecycle","destroy","binary-data"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}