sidorares/node-mysql2 · error · Error

AuthPluginMoreData received but no auth plugin instance…

Error message

AuthPluginMoreData received but no auth plugin instance found

What it means

In authSwitchRequestMoreData (lib/commands/auth_switch.js:130-134), the driver received an AuthSwitchRequestMoreData packet (server continuing a multi-step auth exchange) but connection._authPlugin was never set — meaning the prior AuthSwitchRequest step did not instantiate a plugin. This is an internal sequencing error: the more-data packet arrived without the initial switch request having populated the plugin instance.

Solutions

  1. Migrate off the deprecated authSwitchHandler to the authPlugins config API, which keeps _authPlugin consistent across round-trips.
  2. Ensure no two handshakes race on the same socket (avoid sharing connections across async contexts during connect).
  3. Upgrade mysql2 and verify the server version; report if it persists on stock latest.

Example fix

// before: deprecated handler that desyncs multi-roundtrip plugins
createConnection({ authSwitchHandler: (data, cb) => cb(null, myData) });

// after: plugin factory that handles all round-trips consistently
createConnection({ authPlugins: { my_plugin: myPluginFactory } });
Defensive patterns

Strategy: try-catch

Try / catch

try { await conn.connect(); } catch (e) { if (/no auth plugin instance found/.test(e.message)) { /* stop using deprecated authSwitchHandler */ } throw e; }

Prevention

When it happens

Trigger: A legacy authSwitchHandler is set (it returns early at line 118-128 and never sets _authPlugin, yet the server sends more-data that bypasses the legacy handler); a race where the connection is reset between the switch request and the more-data packet; a server that sends more-data without a preceding switch request.

Common situations: Using the deprecated authSwitchHandler callback API combined with a multi-roundtrip plugin; pooled connection reused mid-handshake; a proxy reordering auth packets.

Related errors


AI-assisted analysis of sidorares/node-mysql2@8b1f829d37 (2026-08-11). Data as JSON: /api/errors/d937c0fc42d79f8a. Report an issue: GitHub.

Appendix: source

Thrown at lib/commands/auth_switch.js:131

}

function authSwitchRequestMoreData(packet, connection, command) {
  const { data } = Packets.AuthSwitchRequestMoreData.fromPacket(packet);

  if (connection.config.authSwitchHandler) {
    const legacySwitchHandler = connection.config.authSwitchHandler;
    warnLegacyAuthSwitch();
    legacySwitchHandler({ pluginData: data }, (err, data) => {
      if (err) {
        return authSwitchPluginError(err, command);
      }
      connection.writePacket(new Packets.AuthSwitchResponse(data).toPacket());
    });
    return;
  }

  if (!connection._authPlugin) {
    throw new Error(
      'AuthPluginMoreData received but no auth plugin instance found'
    );
  }
  Promise.resolve(connection._authPlugin(data))
    .then((data) => {
      if (data) {
        connection.writePacket(new Packets.AuthSwitchResponse(data).toPacket());
      }
    })
    .catch((err) => {
      authSwitchPluginError(err, command);
    });
}

module.exports = {
  authSwitchRequest,
  authSwitchRequestMoreData,
  getAuthPlugin,

View on GitHub (pinned to 8b1f829d37)