{"record":{"id":"8917b1cadf4fdc9a","repo":"cube-js/cube","slug":"cubeserver-is-not-started","errorCode":null,"errorMessage":"CubeServer is not started.","messagePattern":"CubeServer is not started\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cubejs-server/src/server.ts","lineNumber":179,"sourceCode":"  }\n\n  // @internal\n  public async getDriver(ctx: DriverContext): Promise<BaseDriver> {\n    return this.core.getDriver(ctx);\n  }\n\n  public async close() {\n    try {\n      if (this.socketServer) {\n        await this.socketServer.close();\n      }\n\n      if (this.sqlServer) {\n        await this.sqlServer.close();\n      }\n\n      if (!this.server) {\n        throw new Error('CubeServer is not started.');\n      }\n\n      await util.promisify(this.server.close)();\n      this.server = null;\n\n      await this.core.releaseConnections();\n    } catch (e: any) {\n      if (this.core.event) {\n        await this.core.event('Dev Server Fatal Error', {\n          error: (e.stack || e.message || e).toString()\n        });\n      }\n\n      throw e;\n    }\n  }\n\n  /**","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-server/src/server.ts#L161-L197","documentation":"CubeServer.close() throws this when the underlying HTTP server instance is null, meaning the server was never started (or was already closed). close() checks this.server after closing the SQL server and aborts if there is nothing to stop. It guards against calling shutdown on a CubeServer that has not been initialized via listen().","triggerScenarios":"Calling server.close() before server.listen() was ever called, or calling close() twice — the first close sets this.server = null, so the second call hits the throw.","commonSituations":"Shutdown handlers (SIGTERM/SIGINT) that call close() unconditionally while the server failed to boot; test teardown calling close() on a server that never started due to an earlier error; double-invocation of graceful shutdown logic.","solutions":["Ensure server.listen() completed successfully before calling close()","Guard close() calls with a null check on the server or a boolean started flag","In shutdown handlers, track whether the server was started and skip close() otherwise","Wrap close() in try/catch and ignore this specific error in cleanup paths"],"exampleFix":"// before\nconst server = new CubeServer(options);\nprocess.on('SIGTERM', () => server.close());\n\n// after\nconst server = new CubeServer(options);\nserver.listen();\nlet started = false;\nserver.listen().then(() => { started = true; });\nprocess.on('SIGTERM', () => { if (started) server.close(); });","handlingStrategy":"validation","validationCode":"if (typeof server.close === 'function' && server['server']) {\n  await server.close();\n}","typeGuard":"function isStarted(server: CubeServer & { server?: unknown }): boolean {\n  return (server as any).server != null;\n}","tryCatchPattern":"try {\n  await server.close();\n} catch (e) {\n  if (e.message !== 'CubeServer is not started.') throw e;\n  // already stopped / never started: safe to ignore in cleanup\n}","preventionTips":["Always call listen() before registering shutdown hooks that call close()","Use a single shutdown path guarded by a boolean/idempotent promise","In tests, use afterAll/afterEach teardown that tolerates a never-started server","Log whether the server started to make shutdown ordering visible"],"tags":["lifecycle","server-shutdown","cubejs-server"],"backgroundTag":"server-not-started","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}