{"record":{"id":"78deeb3480629741","repo":"neoclide/coc.nvim","slug":"client-got-disposed-and-can-t-be-restarted","errorCode":null,"errorMessage":"Client got disposed and can't be restarted.","messagePattern":"Client got disposed and can't be restarted\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/language-client/client.ts","lineNumber":989,"sourceCode":"        }\n      })\n    })\n  }\n\n  public get started(): boolean {\n    return this.$state != ClientState.Initial\n  }\n\n  public isRunning(): boolean {\n    return this.$state === ClientState.Running\n  }\n  /**\n   * @internal\n   */\n\n  public async _start(): Promise<void> {\n    if (this._disposed === 'disposing' || this._disposed === 'disposed') {\n      throw new Error(`Client got disposed and can't be restarted.`)\n    }\n    if (this.$state === ClientState.Stopping) {\n      throw new Error(`Client is currently stopping. Can only restart a full stopped client`)\n    }\n    // We are already running or are in the process of getting up\n    // to speed.\n    if (this._onStart !== undefined) {\n      return this._onStart\n    }\n    this._rootPath = this.resolveRootPath()\n\n    const [promise, resolve, reject] = this.createOnStartPromise()\n    this._onStart = promise\n\n    this._diagnostics = undefined\n\n    // When we start make all buffer handlers pending so that they\n    // get added.","sourceCodeStart":971,"sourceCodeEnd":1007,"githubUrl":"https://github.com/neoclide/coc.nvim/blob/50e974d9692461a69147d5cab146a8d3e439abe4/src/language-client/client.ts#L971-L1007","documentation":"LanguageClient._start() throws this when the client has already been disposed (this._disposed is 'disposing' or 'disposed') and someone attempts to start it again. vscode-languageserver library clients are single-use: once stopped/disposed they cannot be restarted, and coc throws instead of silently failing.","triggerScenarios":"Calling client.start() (or restart that routes to _start) after client.stop()/dispose() completed or while dispose is in progress; coc's client manager restarting a server whose client instance was already disposed; calling start concurrently with a stop.","commonSituations":"Custom code or an extension holding a reference to a LanguageClient and calling start after stop; server shutdown triggered by :CocRestart while an async start was pending; race between workspace folder changes disposing clients and pending onDidChangeWorkspaceFolder handlers starting them.","solutions":["Create a fresh LanguageClient instance instead of restarting the disposed one.","Track client state before calling start: only start when _disposed is undefined and state is not running.","Serialize start/stop calls (await stop fully, then construct a new client).","Run :CocRestart, which rebuilds client instances rather than reusing disposed ones."],"exampleFix":"// before\nawait client.stop()\nawait client.start() // throws: client disposed\n\n// after\nawait client.stop()\nclient = createClient() // build a new instance\nawait client.start()","handlingStrategy":"try-catch","validationCode":"// only start when not disposed (internal check pattern)\nfunction canStart(client: LanguageClient): boolean {\n  return (client as any)._disposed === undefined\n}","typeGuard":"function isStartable(client: LanguageClient): boolean {\n  const disposed = (client as any)._disposed\n  return disposed !== 'disposing' && disposed !== 'disposed'\n}","tryCatchPattern":"try {\n  await client.start()\n} catch (e) {\n  if (String(e).includes('got disposed')) {\n    client = createNewClient() // rebuild instead of restarting\n    await client.start()\n  }\n}","preventionTips":["Treat LanguageClient as single-use: never call start() after stop()/dispose().","Create a new client instance for every restart cycle.","Serialize start/stop calls; never fire start while a stop is pending.","Use :CocRestart rather than manually restarting held client references."],"tags":["language-client","lifecycle","disposed","lsp"],"backgroundTag":"client-disposed-cannot-restart","analyzedSha":"50e974d9692461a69147d5cab146a8d3e439abe4","analyzedAt":"2026-08-31T11:17:23.966Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}