{"record":{"id":"88d8efb9a554cdc6","repo":"sidorares/node-mysql2","slug":"unexpected-data-in-authmoredata-packet-received-by-88d8ef","errorCode":null,"errorMessage":"Unexpected data in AuthMoreData packet received by ${PLUGIN_NAME} plugin in state ${state}","messagePattern":"Unexpected data in AuthMoreData packet received by (.+?) plugin in state (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/auth_plugins/sha256_password.js","lineNumber":70,"sourceCode":"          if (pluginOptions.serverPublicKey) {\n            return authWithKey(pluginOptions.serverPublicKey);\n          }\n\n          state = STATE_WAIT_SERVER_KEY;\n          return REQUEST_SERVER_KEY_PACKET;\n\n        case STATE_WAIT_SERVER_KEY:\n          if (pluginOptions.onServerPublicKey) {\n            pluginOptions.onServerPublicKey(data);\n          }\n          return authWithKey(data);\n        case STATE_FINAL:\n          throw new Error(\n            `Unexpected data in AuthMoreData packet received by ${PLUGIN_NAME} plugin in STATE_FINAL state.`\n          );\n      }\n\n      throw new Error(\n        `Unexpected data in AuthMoreData packet received by ${PLUGIN_NAME} plugin in state ${state}`\n      );\n    };\n  };\n","sourceCodeStart":52,"sourceCodeEnd":75,"githubUrl":"https://github.com/sidorares/node-mysql2/blob/8b1f829d3706404ab372cf97bd77ebcf86578d97/lib/auth_plugins/sha256_password.js#L52-L75","documentation":"Defensive catch-all at the bottom of sha256_password's switch (lib/auth_plugins/sha256_password.js:70-72). All defined states (STATE_INITIAL=0, STATE_WAIT_SERVER_KEY=1, STATE_FINAL=-1) have explicit cases, so reaching this throw implies the state variable was corrupted — an internal invariant violation, not a user-config issue.","triggerScenarios":"Plugin closure shared across connections causing state bleed; a forked/patched plugin that mutates state incorrectly; memory corruption.","commonSituations":"Custom code caching the plugin factory result and reusing it; rarely, a genuine bug worth reporting upstream.","solutions":["Do not reuse a plugin instance across connections; let the driver instantiate per-connection.","Reproduce on stock mysql2 latest and file an issue with server version and config."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await conn.connect(); } catch (e) { if (/sha256_password.*state/.test(e.message)) { conn.destroy(); } throw e; }","preventionTips":["Do not reuse plugin instances across connections.","File an upstream issue with server version if hit on stock mysql2."],"tags":["authentication","sha256-password","internal","defensive"],"backgroundTag":null,"analyzedSha":"8b1f829d3706404ab372cf97bd77ebcf86578d97","analyzedAt":"2026-08-11T02:54:28.964Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}