Skip to content

New connection v2.0 #204

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
akd3vs opened this issue May 20, 2012 · 27 comments
Closed

New connection v2.0 #204

akd3vs opened this issue May 20, 2012 · 27 comments

Comments

@akd3vs
Copy link

akd3vs commented May 20, 2012

I'm trying to connect and nothings happend, trows this error
Object { code="PROTOCOL_PARSER_EXCEPTION", fatal=true }
and console.log() to the object I notice this: Object # has no method 'EofPacket'.
do i have to go back to 0.9.6?
By the way, you have an error here -> https://github.com/felixge/node-mysql/tree/v2.0#server-disconnects it has 3 n's in connection = mysql.createConnnection(connection.config);

felixge added a commit that referenced this issue May 20, 2012
Reported in #204
@felixge
Copy link
Collaborator

felixge commented May 20, 2012

Thanks for reporting this. Can you please add a little more information:

  • A minimal code snippet that triggers this error
  • The stack trace you see when the error is thrown
  • The MySQL version you are using
  • The node version you are using

do i have to go back to 0.9.6?

No, I'll fix this problem if you provide me with more information.

Thanks for reporting the typo, that's fixed now.

@akd3vs
Copy link
Author

akd3vs commented May 20, 2012

registry.connect(function(err){
                if(err) socket.emit('debug',err,'db registry error 1');

I have 2 connections, even if I don't connect manually.
Object { code="PROTOCOL_PARSER_EXCEPTION", fatal=true }
I'm not sure what is the stack trace. I'm sorry, english isn't my first language. Is what err throws me
MySQL version: 5.5.24
Node version: 0.6.15.

If you say me to update my node I'll and sorry if that isn't the track trace.

@akd3vs
Copy link
Author

akd3vs commented May 20, 2012

{ config: 
   { host: 'localhost',
     port: 3306,
     user: 'root',
     password: 'password',
     database: 'db',
     debug: false,
     typeCast: true,
     maxPacketSize: 16777216,
     charsetNumber: 192,
     clientFlags: 194511 },
  _socket: 
   { _handle: null,
     _pendingWriteReqs: 0,
     _flags: 0,
     _connectQueueSize: 0,
     destroyed: true,
     errorEmitted: false,
     bytesRead: 87,
     bytesWritten: 75,
     allowHalfOpen: undefined,
     _connecting: false,
     writable: false,
     _events: { error: [Object] },
     _pipeCount: 0,
     readable: false,
     _connectQueue: null,
     _idleNext: null,
     _idlePrev: null,
     _idleTimeout: -1 },
  _protocol: 
   { readable: true,
     writable: true,
     _parser: 
      { _buffer: <Buffer 01 00 00 02 fe>,
        _offset: 9,
        _packetEnd: 5,
        _packetHeader: [Object],
        _packetParser: [Function],
        _encoding: 'utf-8',
        _paused: false },
     _config: 
      { host: 'localhost',
        port: 3306,
        user: 'root',
        password: 'password',
        database: 'db',
        debug: false,
        typeCast: true,
        maxPacketSize: 16777216,
        charsetNumber: 192,
        clientFlags: 194511 },
     _callback: null,
     _fatalError: { [TypeError: Object #<Handshake> has no method 'EofPacket'] code: 'PROTOCOL_PARSER_EXCEPTION', fatal: true },
     _quitSequence: null,
     _destroyed: false,
     _queue: [ [Object], [Object] ],
     _events: { close: [Object], unhandledError: [Function] },
     _pipeCount: 1 },
  _connectCalled: true }

this is what console.log give me of the object

@felixge
Copy link
Collaborator

felixge commented May 20, 2012

I'm not sure what is the stack trace. I'm sorry, english isn't my first language. Is what err throws me

The stack trace is the file names and line numbers you see when throwing an exception. To see it, you must change:

if(err) socket.emit('debug',err,'db registry error 1');

to

if(err) throw err;

Can you please do that and show me the output? Thanks a lot.

@felixge
Copy link
Collaborator

felixge commented May 20, 2012

One idea: Are you calling connect() multiple times on the same object?

@akd3vs
Copy link
Author

akd3vs commented May 20, 2012

I'm calling just 1 time.

io.sockets.on('connection', function (socket){
    socket.on('init',function(data,fn){
        registry.connect(function(err){
            if(err) throw err;
        });

node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Object # has no method 'EofPacket'
at Protocol._parsePacket (/root/local/node/lib/node_modules/mysql/lib/protocol/Protocol.js:143:23)
at Parser._packetParser (native)
at Parser.write (/root/local/node/lib/node_modules/mysql/lib/protocol/Parser.js:42:10)
at Protocol.write (/root/local/node/lib/node_modules/mysql/lib/protocol/Protocol.js:31:18)
at Socket.ondata (stream.js:38:26)
at Socket.emit (events.js:67:17)
at TCP.onread (net.js:367:14)

@mscdex
Copy link
Contributor

mscdex commented May 21, 2012

@akd3vs Judging by your code it looks like connect() is called on the same instance every time someone connects via socket.io. You might try connecting on script startup and then just perform your queries when people connect via socket.io, etc.

@akd3vs
Copy link
Author

akd3vs commented May 21, 2012

@mscdex already do that and the same error, also I notice this in forever log
<-- EofPacket (#2)
{ fieldCount: 254, warningCount: NaN, serverStatus: NaN }
I hope this can help

@felixge
Copy link
Collaborator

felixge commented May 22, 2012

@akd3vs please try again with 95748f3. If you get a 'PROTOCOL_ENQUEUE_HANDSHAKE_TWICE' error, you are still calling connect() more than once - this is not supported.

@akd3vs
Copy link
Author

akd3vs commented May 22, 2012

@felixge I still getting the error, what I do is clone the repository and checkout 95748f3, then make npm install and verify the file changes in node_modules.

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
TypeError: Object #<Handshake> has no method 'EofPacket'
    at Protocol._parsePacket (/root/local/node/lib/node_modules/mysql/lib/protocol/Protocol.js:157:23)
    at Parser._packetParser (native)
    at Parser.write (/root/local/node/lib/node_modules/mysql/lib/protocol/Parser.js:42:10)
    at Protocol.write (/root/local/node/lib/node_modules/mysql/lib/protocol/Protocol.js:31:18)
    at Socket.ondata (stream.js:38:26)
    at Socket.emit (events.js:67:17)
    at Pipe.onread (net.js:367:14)

Edit1: I created another script and i'm sure, is not a double connect.

@felixge felixge reopened this May 31, 2012
@felixge
Copy link
Collaborator

felixge commented May 31, 2012

I think I know what the issue is. This is very likely a server that tries to use the old MySQL authentication mechanism. I dropped support for this in 2.0, but I think I'll bring it back.

@akd3vs
Copy link
Author

akd3vs commented May 31, 2012

Thank you for try it again. :) I really like the Streaming query rows. A little doubt, i hope you can tell if it is in plans or you like the idea:

$this->db->where('name', $name);
$this->db->where('title', $title);
$this->db->where('status', $status); 

// WHERE name = 'Joe' AND title = 'boss' AND status = 'active'

http://codeigniter.com/user_guide/database/active_record.html#select
Without this I have to make an ajax request. Anyway, I hope you wanna add this feature in the future.

@felixge
Copy link
Collaborator

felixge commented May 31, 2012

@akd3vs I won't add many ORM-like features, but you can do this in 2.0:

var conditions = {name: 'my name', title: 'my title', status: 'my status'};
connection.query('SELECT * FROM users WHERE ?', conditions, function(err, rows) {
  // ...
});

@akd3vs
Copy link
Author

akd3vs commented Jun 1, 2012

Thank you! Now I can connect and do querys and everything. Also I update the password of the user with PASSWORD(). Thank you again :)

@felixge
Copy link
Collaborator

felixge commented Jun 1, 2012

@akd3vs happy to hear that : ).

@ibnmasud
Copy link

ibnmasud commented Jun 6, 2012

I still cannot connect, get the same error :(
And I am not using old_password...

@felixge
Copy link
Collaborator

felixge commented Jun 6, 2012

@ibnmasud what version are you using? You'll have to get the latest version from git for this fix.

@devtin
Copy link

devtin commented Jun 17, 2012

Hi,

I have the following code to attempt to connect to 'somehost.com' which is using the old_password algorithm. I've set the flag 'insecurePassword' to true, but I keep getting this error: 'TypeError: Object # has no method 'EofPacket''.

Any idea?

var GolAGOl = new (function()
{
var MySQL = new (function()
{
var config =
{
'host' : 'somehost.com
'user' : 'someuser',
'password' : 'somepassword',
'port' : '3306',
'database' : 'golagol',
'insecureAuth' : true
};

    var MySQLDriver = require('mysql'),my,tries = 0,maxTries = 3,rca,connected = false,queryStack = new Array();

    function connect(c)
    {
        my =  MySQLDriver.createConnection(config);
        my.connect((function(c){return function(err){if(err){console.log('ERROR: '+err);retryConnection();}else{myConnected();}}})(c));
    }

    function retryConnection()
    {
        connected = false;
        tries++;

        if (tries >= maxTries)
        {
            console.log('Max attempts reached');
            return;
        }

        console.log('RETRYING CONNECTION');

        try{clearTimeout(rca)}catch(e){}
        rca = setTimeout(connect,1000);
    }

    function flushQueries()
    {
        while (queryStack.length != 0)
        {
            queryStack[0]();
            queryStack.splice(0,1);
        }
    }

    function myConnected()
    {
        console.log("CONNECTED");

        connected = true;
        my.on('close',retryConnection);
        tries = 0;
        flushQueries();
    }

    function query(q,c)
    {
        if (!connected)
        {
            queryStack.push((function(q,c){return function(){query(q,c);}})(q,c));
            return;
        }

        my.query(q,c);
    }

    connect();
    query("SELECT * FROM user;",function(err,rows){console.log(rows);});
    this.query = query;
})();

this.MySQL = MySQL;

})();

Here is the stack trace

ERROR: TypeError: Object # has no method 'EofPacket'

/Users/tin/Sites/golagol/www/js/node.js:29
on(c){return function(err){if(err){console.log('ERROR: '+err);throw err;retryC
^
TypeError: Object # has no method 'EofPacket'
at Protocol._parsePacket (/Users/tin/Sites/golagol/www/js/node_modules/mysql/lib/protocol/Protocol.js:156:23)
at Parser._packetParser (native)
at Parser.write (/Users/tin/Sites/golagol/www/js/node_modules/mysql/lib/protocol/Parser.js:51:12)
at Protocol.write (/Users/tin/Sites/golagol/www/js/node_modules/mysql/lib/protocol/Protocol.js:31:18)
at Socket.ondata (stream.js:38:26)
at Socket.emit (events.js:67:17)
at TCP.onread (net.js:367:14)
--------------------
at Handshake.Sequence (/Users/tin/Sites/golagol/www/js/node_modules/mysql/lib/protocol/sequences/Sequence.js:15:21)
at new Handshake (/Users/tin/Sites/golagol/www/js/node_modules/mysql/lib/protocol/sequences/Handshake.js:9:12)
at Protocol.handshake (/Users/tin/Sites/golagol/www/js/node_modules/mysql/lib/protocol/Protocol.js:44:50)
at Connection.connect (/Users/tin/Sites/golagol/www/js/node_modules/mysql/lib/Connection.js:38:18)
at connect (/Users/tin/Sites/golagol/www/js/node.js:29:16)
at new (/Users/tin/Sites/golagol/www/js/node.js:79:9)
at new (/Users/tin/Sites/golagol/www/js/node.js:12:17)
at Object. (/Users/tin/Sites/golagol/www/js/node.js:10:15)
at Module._compile (module.js:446:26)
at Object..js (module.js:464:10)

@felixge
Copy link
Collaborator

felixge commented Jun 18, 2012

@tin-r which node-mysql version are you using?

@devtin
Copy link

devtin commented Jun 18, 2012

Hi, i'm using node v0.6.19 and node-mysql v0.9

@felixge
Copy link
Collaborator

felixge commented Jun 18, 2012

@tin-r That's impossible. node-mysql v0.9 had no createConnection method. Can you re-check?

You'll have to use the latest node-mysql from master for the feature you need, a new npm release is coming soon.

@devtin
Copy link

devtin commented Jun 18, 2012

@felixge I'm sorry, I think I was still asleep at the time I answered. The node-mysql version is v2.0.0-alpha2 (unreleased)

@felixge
Copy link
Collaborator

felixge commented Jun 18, 2012

@tin-r alright, then could you try upgrading to the latest version from github?

@devtin
Copy link

devtin commented Jun 19, 2012

Thanks a lot @felixge it's now working.

If it helps anyone else, at first, I didn't know how worked node modules. I installed node-mysql with the node package manager, which, seems not to has the most recent update supporting old mysql passwords.

I just downloaded the last version from github and extracted the files into a folder called "mysql". Please notice that, since you're not installing node-mysql from the npm (node package manager) when you're importing it into your project, you're gonna have to call the "index.js" file in the packet instead of calling "mysql", in my case it would be something like require('./mysql/index.js').

When I first ran my script after doing this changes, an exception were thrown indicating that the module "require-all" wasn't found. To fix this, I entered "npm install require-all", I ran my script again and voilá! Smooth!

To use with mysql old passwords, make sure to set the flag 'insecureAuth' to true.

@akd3vs
Copy link
Author

akd3vs commented Jun 19, 2012

@tin-r Or you could install as normally "npm install path/to/node-mysql"

@devtin
Copy link

devtin commented Jun 19, 2012

Yeah! Or that @akd3vs : )

@felixge
Copy link
Collaborator

felixge commented Jun 20, 2012

Ok, closing this. Btw. the proper way to install the latest version from Github is:

npm install git://github.com/felixge/node-mysql.git

I just added this to the Readme in a42a2eb .

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

No branches or pull requests

5 participants