{"record":{"id":"9dfd83841bb911ea","repo":"cube-js/cube","slug":"cannot-call-method-on-instancename-the-name","errorCode":null,"errorMessage":"Cannot call method on ${instanceName}. The '${name}' has been cleaned up and is no longer available.","messagePattern":"Cannot call method on (.+?)\\. The '(.+?)' has been cleaned up and is no longer available\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cubejs-backend-shared/src/disposedProxy.ts","lineNumber":20,"sourceCode":" * Creates a proxy object that throws an error on any property access.\n * Used as a safeguard after disposal to catch dangling references.\n */\nexport function disposedProxy(name: string, instanceName: string): any {\n  return new Proxy({}, {\n    get(_target: object, prop: string | symbol): never {\n      throw new Error(\n        `Cannot access property '${String(prop)}' on ${instanceName}. ` +\n        `The '${name}' has been cleaned up and is no longer available.`\n      );\n    },\n    set(_target: object, prop: string | symbol): never {\n      throw new Error(\n        `Cannot set property '${String(prop)}' on ${instanceName}. ` +\n        `The '${name}' has been cleaned up and is no longer available.`\n      );\n    },\n    apply(): never {\n      throw new Error(\n        `Cannot call method on ${instanceName}. ` +\n        `The '${name}' has been cleaned up and is no longer available.`\n      );\n    },\n    has(_target: object, _prop: string | symbol): never {\n      throw new Error(\n        `Cannot check property existence on ${instanceName}. ` +\n        `The '${name}' has been cleaned up and is no longer available.`\n      );\n    },\n    ownKeys(): never {\n      throw new Error(\n        `Cannot enumerate properties on ${instanceName}. ` +\n        `The '${name}' has been cleaned up and is no longer available.`\n      );\n    },\n    getPrototypeOf(): never {\n      throw new Error(","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-backend-shared/src/disposedProxy.ts#L2-L38","documentation":"Cube replaces disposed internal objects with a proxy from disposedProxy() that throws on any interaction. The `apply` trap fires when the proxy is invoked as a function, meaning code held a reference to a method/object belonging to something that has already been cleaned up (e.g. a disposed queue, orchestrator, or driver). It is a deliberate safeguard to surface dangling references after teardown instead of failing silently or crashing obscurely.","triggerScenarios":"Calling a method on an instance whose owner was disposed via its cleanup/dispose path, so the property now resolves to the disposed proxy. E.g. keeping a reference to an orchestrator's queryQueue and invoking it after the server was shut down.","commonSituations":"Holding long-lived references to Cube internals across server restarts or hot reloads; calling a method asynchronously after the instance's dispose() already ran (a pending setTimeout, promise chain, or event listener); unit tests reusing captured references between test cases.","solutions":["Find what created the disposed instance and stop using references to it after its dispose/cleanup was called.","Re-acquire the instance from the live server/orchestrator instead of caching it at startup.","Cancel pending timers, listeners, or in-flight async work during teardown so they never invoke the disposed object.","Guard usage with a liveness check or wrap the call in try/catch to handle races during shutdown."],"exampleFix":"// before\nconst queue = server.queryQueue;\nserver.dispose();\nsetTimeout(() => queue.execute(query), 1000); // throws\n\n// after\nlet queue = server.queryQueue;\nserver.dispose();\nqueue = null;\nsetTimeout(() => { if (queue) queue.execute(query); }, 1000);","handlingStrategy":"try-catch","validationCode":"if (instanceRef === null || instanceRef === undefined) {\n  throw new Error('Reference already disposed; re-acquire it.');\n}\nconst probe = {};\ntry {\n  // liveness probe: disposed proxy throws on 'has'\n  'anything' in instanceRef;\n} catch (e) {\n  throw new Error('Instance was disposed, do not call methods on it.');\n}","typeGuard":"function isAlive<T extends object>(ref: T | null | undefined): ref is T {\n  if (ref == null) return false;\n  try {\n    'livenessProbe' in ref;\n    return true;\n  } catch {\n    return false;\n  }\n}","tryCatchPattern":"try {\n  disposedInstance.someMethod();\n} catch (e) {\n  if (e.message.includes('has been cleaned up and is no longer available')) {\n    // re-acquire a live instance or abort the in-flight work\n    instanceRef = null;\n    return;\n  }\n  throw e;\n}","preventionTips":["Null out references in the same place you call dispose()/cleanup.","Cancel timers, listeners, and in-flight promises during teardown.","Prefer fetching internals from the live server object over caching them at startup.","In tests, recreate fixtures per test instead of sharing disposed instances."],"tags":["disposed-object","lifecycle","proxy","cleanup"],"backgroundTag":"use-after-dispose","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}