Skip to content

changeUser: Cannot call method 'scrambleBuff' of undefined #374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
clloyd opened this issue Jan 10, 2013 · 9 comments · Fixed by #618
Closed

changeUser: Cannot call method 'scrambleBuff' of undefined #374

clloyd opened this issue Jan 10, 2013 · 9 comments · Fixed by #618

Comments

@clloyd
Copy link

clloyd commented Jan 10, 2013

I'm getting the above error why trying to run changeUser on a newly connected mysql connection.

Editing Protocall.js to pass this._handshakeInitializationPacket into .start() seems to fix this.

@dresende
Copy link
Collaborator

Versions please. OS, database, node, ...

@clloyd
Copy link
Author

clloyd commented Jan 16, 2013

Mac OSX 10.8.2, node v0.8.17, mysql 5.5.27

@felixge
Copy link
Collaborator

felixge commented Jan 16, 2013

IIRC there is a bug, you can't call changeUser() until the connection has been established.

@dresende
Copy link
Collaborator

@clloyd can you show an example? Did you trigger .connect() or did you just .createConnection() and then .changeUser() ?

@innc
Copy link

innc commented Apr 1, 2013

I encountered same error message: (openSuse 12.2, node v0.8.18, mysql 5.5.30)
I dont know, if these infos will help...

myCode snippet:
...
mysqlPool.getConnection(function(err, connection)
{
console.log('Connection (dbKeysAndCommentsStore):\n', connection);
connection.changeUser({user : 'guestusername', password : 'guestpassord', database : 'INFORMATION_SCHEMA'},
function(err) {
if(err){throw err;}
else{console.log('Connection after change (dbKeysAndCommentsStore):\n', connection);}
});
connection.query(.... connection.end(););
});

Thats my connection object, before i do connection.changeUser:
(in this case user, password and database is identically to the user at connection.changeUser)

{ domain: null,
_events: { end: [Function] },
_maxListeners: 10,
config:
{ host: 'localhost',
port: 3306,
socketPath: undefined,
user: 'guestusername',
password: 'guestpassword',
database: 'INFORMATION_SCHEMA',
insecureAuth: false,
supportBigNumbers: false,
debug: undefined,
timezone: 'local',
flags: '',
queryFormat: undefined,
pool:
{ config: [Object],
_allConnections: [Object],
_freeConnections: [Object],
_connectionQueue: [],
_closed: false },
typeCast: true,
maxPacketSize: 0,
charsetNumber: 33,
clientFlags: 193487 },
_socket:
{ domain: null,
_events:
{ data: [Function: ondata],
end: [Object],
close: [Object],
error: [Object],
drain: [Function: ondrain] },
_maxListeners: 10,
_handle:
{ writeQueueSize: 0,
owner: [Circular],
onread: [Function: onread] },
_pendingWriteReqs: 0,
_flags: 0,
_connectQueueSize: 0,
destroyed: false,
errorEmitted: false,
bytesRead: 8001,
_bytesDispatched: 756,
allowHalfOpen: undefined,
_connecting: false,
writable: true,
readable: true,
_paused: false },
_protocol:
{ domain: null,
_events:
{ drain: [Object],
error: [Object],
end: [Object],
close: [Object],
data: [Function: ondata],
unhandledError: [Function] },
_maxListeners: 10,
readable: true,
writable: true,
_config:
{ host: 'localhost',
port: 3306,
socketPath: undefined,
user: 'guestusername',
password: 'guestpassword',
database: 'INFORMATION_SCHEMA',
insecureAuth: false,
supportBigNumbers: false,
debug: undefined,
timezone: 'local',
flags: '',
queryFormat: undefined,
pool: [Object],
typeCast: true,
maxPacketSize: 0,
charsetNumber: 33,
clientFlags: 193487 },
_connection: [Circular],
_callback: null,
_fatalError: null,
_quitSequence: null,
_handshakeSequence:
{ domain: null,
_events: [Object],
_maxListeners: 10,
_callback: [Function],
_ended: true,
_callSite: ' at Handshake.Sequence (/myDirectory/node_modules/mysql/lib/protocol/sequences/Sequence.js:15:21)\n at new Handshake (/myDirectory/node_modules/mysql/lib/protocol/sequences/Handshake.js:9:12)\n at Protocol.handshake (/myDirectory/node_modules/mysql/lib/protocol/Protocol.js:41:50)\n at Connection.connect (/myDirectory/node_modules/mysql/lib/Connection.js:63:18)\n at Pool.getConnection (/myDirectory/node_modules/mysql/lib/Pool.js:30:16)\n at Object.dbKeysAndCommentsStore.main (/myDirectory/modules/dbKeysAndCommentsStore.js:14:23)\n at Object.webInfSys.main (/myDirectory/js/server/webInfSys.js:29:36)\n at Object. (/myDirectory/js/server/webInfSys.js:82:11)\n at Module._compile (module.js:449:26)\n at Object.Module._extensions..js (module.js:467:10)',
_config: [Object],
_handshakeInitializationPacket: [Object] },
_destroyed: false,
_queue: [],
_handshakeInitializationPacket:
{ protocolVersion: 10,
serverVersion: '5.5.30-log',
threadId: 128,
scrambleBuff1: <Buffer 38 49 45 60 36 29 6a 5c>,
filler1: <Buffer 00>,
serverCapabilities1: 63487,
serverLanguage: 33,
serverStatus: 2,
serverCapabilities2: 32783,
scrambleLength: 21,
filler2: <Buffer 00 00 00 00 00 00 00 00 00 00>,
scrambleBuff2: <Buffer 6c 2b 2e 46 56 5e 53 67 2e 4d 77 30>,
filler3: <Buffer 00>,
pluginData: 'mysql_native_password' },
_parser:
{ _supportBigNumbers: false,
_buffer: <Buffer 01 00 00 01 02 4a 00 00 02 03 64 65 66 12 69 6e 66 6f 72 6d 61 74 69 6f 6e 5f 73 63 68 65 6d 61 07 43 4f 4c 55 4d 4e 53 07 43 4f 4c 55 4d 4e 53 0a 74 61 ...>,
_longPacketBuffers: [],
_offset: 638,
_packetEnd: null,
_packetHeader: null,
_onPacket: [Function],
_nextPacketNumber: 24,
_encoding: 'utf-8',
_paused: false } },
_connectCalled: true,
_realEnd: [Function],
end: [Function],
_realDestroy: [Function],
destroy: [Function] }

Exception at function dbKeysAndCommentsStore.main: TypeError: Cannot call method 'scrambleBuff' of undefined
TypeError: Cannot call method 'scrambleBuff' of undefined
at ChangeUser.start (/myDirectory/node_modules/mysql/lib/protocol/sequences/ChangeUser.js:19:52)
at Protocol._enqueue (/myDirectory/node_modules/mysql/lib/protocol/Protocol.js:108:14)
at Protocol.changeUser (/myDirectory/node_modules/mysql/lib/protocol/Protocol.js:49:15)
at Connection.changeUser (/myDirectory/node_modules/mysql/lib/Connection.js:78:25)
at /myDirectory/modules/dbKeysAndCommentsStore.js:19:28
at Pool.getConnection (/myDirectory/node_modules/mysql/lib/Pool.js:25:5)
at Object.dbKeysAndCommentsStore.main (/myDirectory/modules/dbKeysAndCommentsStore.js:14:23)
at Object.handle (/myDirectory/modules/constructSQLTable.js:14:36)
at next (/myDirectory/node_modules/express/node_modules/connect/lib/proto.js:199:15)
at next (/myDirectory/node_modules/express/node_modules/connect/lib/proto.js:174:78)

@innc
Copy link

innc commented Apr 14, 2013

I use now (openSuse 12.2, node v0.8.23, mysql 5.5.30)
I tried to add some pseudo code snippet, which causes this error (probably it helps):

Exception at function sendOtherQueryAsUserAccountABC.main:
TypeError: Cannot call method 'scrambleBuff' of undefined
at ChangeUser.start (/myDirectory/node_modules/mysql/lib/protocol/sequences/ChangeUser.js:19:52)
at Protocol._enqueue (/myDirectory/node_modules/mysql/lib/protocol/Protocol.js:108:14)
at Protocol.changeUser (/myDirectory/node_modules/mysql/lib/protocol/Protocol.js:49:15)
at Connection.changeUser (/myDirectory/node_modules/mysql/lib/Connection.js:78:25)
at sendOtherQueryAsUserAccountABC.main (/myDirectory/modules/genFlightplans.js:21:32)
at Pool.getConnection (/myDirectory/node_modules/mysql/lib/Pool.js:25:5)
at Object.sendOtherQueryAsUserAccountABC.main (/myDirectory/modules/sendOtherQueryAsUserAccountABC.js:10:23)
at Object.webInfSys.main2 as _onTimeout
at Timer.list.ontimeout (timers.js:101:19)

Pseudo Code snippet:

main:function()
{
    try
    {
        var mysql = require('mysql');
        var mysqlPool = mysql.createPool
            ({
                host : 'myhost',
                port : 'myport',
                user     : 'myusername',
                password : 'mypassword'
            });

        // at file happens changeUser and query will be sent
        var sendQuery1AsUserAccountXYZ = require('../../modules/sendQuery1AsUserAccountXYZ.js');
        sendQuery1AsUserAccountXYZ.main(mysqlPool);

        setTimeout(function()
        {
            // at file happens another changeUser and other query will be sent
            var sendOtherQueryAsUserAccountABC = require('../../modules/sendOtherQueryAsUserAccountABC.js');
            sendOtherQueryAsUserAccountABC.main(mysqlPool);

        }, 1000);
    }
    catch(exception)
    {
        console.error('Exception at function main2:\n' + exception.stack);
        process.exit(require('../../modules/error.js').EXIT_FAILURE);
    }
    finally
    {
        // done
    }
}

@carlholloway
Copy link

I too have this issue.

node v0.8.16, mysql 5.5.24

The problem is fixed by changing line 109 of Protocol.js to the below:

if (sequence.constructor == Sequences.ChangeUser) {
  sequence.start(this._handshakeInitializationPacket);
} else {
  sequence.start();
}

This logic is already followed at lines 225/226 of the same file, where we specifically pass in the handshake initialization packet as an argument, required for ChangeUser.start()

Thoughts?

@innc
Copy link

innc commented Jul 13, 2013

@carlholloway
Cool, thanks, i tested your fix today at my program and yes, no error message anymore! thumb up
Would be great, if this fix would be inside next release of node-mysql !!!

My test code:

var mysql = require('mysql');
var mysqlPool = mysql.createPool({host : hoststring, port : portnumber, 
                                  user : guestUsername1, password : guestPassword1});
var i = 0;
setInterval(function()
{
  if(i < 40)
  {
    mysqlPool.getConnection(function(err, connection)
    {
      console.log('db keepalive ' + i);
      if(err)
      {
        console.log(err);
        connection.end();
        return false;
      }

      connection.query(queryString);
      connection.end();
      ++i;
    });
  }
  else if(i < 80)
  {
    mysqlPool.getConnection(function(err, connection)
    {
      console.log('db keepalive ' + i);
      if(err)
      {
        console.log(err);
        connection.end();
        return false;
      }

      connection.changeUser(
      {
        user     : guestUsername2,
        password : guestPassword2
      },
      function(err)
      {
        if(err)
        {
          console.error(err.stack);
          throw err;
        }
        else
        {
          connection.query(anotherQueryString);
          connection.end();
          ++i;
        }
      });
    });
  }
}, 1000);

@imjoshholloway
Copy link

+1 for this.

@carlholloway's fix works perfectly.

Node Version: 0.8.18
MySQL Version: 5.6.12

seanmonstar added a commit to seanmonstar/node-mysql that referenced this issue Oct 16, 2013
If the queue is empty before calling a ChangeUser sequence, the sequence will be started without being passed the handshake packet. This makes sure it gets passed.

Additionally, validateEnqueue now has a test that handeshake() was called before changeUser().

fixes mysqljs#374
seanmonstar added a commit to seanmonstar/node-mysql that referenced this issue Oct 16, 2013
If the queue is empty before calling a ChangeUser sequence, the sequence will be started without being passed the handshake packet. This makes sure it gets passed.

Additionally, validateEnqueue now has a test that handeshake() was called before changeUser().

fixes mysqljs#374
seanmonstar added a commit to seanmonstar/node-mysql that referenced this issue Oct 16, 2013
If the queue is empty before calling a ChangeUser sequence, the sequence will be started without being passed the handshake packet. This makes sure it gets passed.

Additionally, validateEnqueue now has a test that handeshake() was called before changeUser().

fixes mysqljs#374
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

6 participants