{"record":{"id":"cb12872b0a6d6a7c","repo":"Automattic/mongoose","slug":"invalid-connection-state-val","errorCode":null,"errorMessage":"Invalid connection state: ${val}","messagePattern":"Invalid connection state: (.+?)","errorType":"validation","errorClass":"MongooseError","httpStatus":null,"severity":"error","filePath":"lib/connection.js","lineNumber":135,"sourceCode":"Object.defineProperty(Connection.prototype, 'readyState', {\n  get: function() {\n    // If connection thinks it is connected, but we haven't received a heartbeat in 2 heartbeat intervals,\n    // that likely means the connection is stale (potentially due to frozen AWS Lambda container)\n    if (\n      this._readyState === STATES.connected &&\n      this._lastHeartbeatAt != null &&\n      // LoadBalanced topology (behind haproxy, including Atlas serverless instances) don't use heartbeats,\n      // so we can't use this check in that case.\n      this.client?.topology?.s?.description?.type !== 'LoadBalanced' &&\n      typeof this.client?.topology?.s?.description?.heartbeatFrequencyMS === 'number' &&\n      Date.now() - this._lastHeartbeatAt >= this.client.topology.s.description.heartbeatFrequencyMS * 2) {\n      return STATES.disconnected;\n    }\n    return this._readyState;\n  },\n  set: function(val) {\n    if (!(val in STATES)) {\n      throw new MongooseError('Invalid connection state: ' + val);\n    }\n\n    if (this._readyState !== val) {\n      this._readyState = val;\n      // [legacy] loop over the otherDbs on this connection and change their state\n      for (const db of this.otherDbs) {\n        db.readyState = val;\n      }\n\n      if (STATES.connected === val) {\n        this._hasOpened = true;\n      }\n\n      this.emit(STATES[val]);\n    }\n  }\n});\n","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/Automattic/mongoose/blob/49cdab01366679723b487ecb754b38570f783289/lib/connection.js#L117-L153","documentation":"Error \"Invalid connection state: ${val}\" thrown in Automattic/mongoose.","triggerScenarios":"Thrown at lib/connection.js:135 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"49cdab01366679723b487ecb754b38570f783289","analyzedAt":"2026-08-21T22:54:00.882Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}