CarnegieLearning / connect-mysql-session

A MySQL session store for node.js connect.
BSD 3-Clause "New" or "Revised" License
41 stars 17 forks source link

Error when deleting sessions #5

Open adamsch1 opened 11 years ago

adamsch1 commented 11 years ago

Howdy - Is this project still alive?

I noticed I was getting an error when connect-mysql-session tried to expire old sessions. I added a little extra logging and thought I would pass it along. Nothing obvious as t owhat is causing it.

/home/shane/slurp/node_modules/connect-mysql-session/lib/connect-mysql-session.js:61 sessions[i].destroy(); ^ TypeError: Object function () { return this.slice(-1)[0]; } has no method 'destroy' at module.exports.get.Session.find.where.sid (/home/shane/slurp/node_modules/connect-mysql-session/lib/connect-mysql-session.js:61:41) at EventEmitter.emit (events.js:126:20) at Query.onSuccess (/home/shane/slurp/node_modules/connect-mysql-session/node_modules/sequelize/lib/sequelize/query.js:54:8) at /home/shane/slurp/node_modules/connect-mysql-session/node_modules/sequelize/lib/sequelize/query.js:22:38 at Query.Client.query (/home/shane/slurp/node_modules/connect-mysql-session/node_modules/sequelize/node_modules/mysql/lib/client.js:108:11) at Query.EventEmitter.emit (events.js:93:17) at Query._handlePacket (/home/shane/slurp/node_modules/connect-mysql-session/node_modules/sequelize/node_modules/mysql/lib/query.js:51:14) at Client._handlePacket (/home/shane/slurp/node_modules/connect-mysql-session/node_modules/sequelize/node_modules/mysql/lib/client.js:312:14) at Parser.EventEmitter.emit (events.js:96:17) at Parser.write.emitPacket (/home/shane/slurp/node_modules/connect-mysql-session/node_modules/sequelize/node_modules/mysql/lib/parser.js:71:14)

{ __definition: { options: { timestamps: true, hasPrimaryKeys: false }, name: 'Session', tableName: 'Sessions', attributes: { sid: 'VARCHAR(255) NOT NULL UNIQUE', expires: 'INT', json: 'TEXT',

yss commented 11 years ago

If you want to delete the current user session, you can use req.session.destroy();

wonderwhy-er commented 11 years ago

Hi, stumbled on this problem too. I know what causing but not sure where exactly problem is.

Basically in my class Array class is extended with custom methods like this Array.prototype.remove_duplicates = function(...

And apparently in this code remove_duplicates ends up in sessions array

                Session.findAll({where: ['expires < ?', Math.round(Date.now() / 1000)]})
                .on('success', function (sessions)
                {
                    if (sessions.length > 0)
                    {
                        console.log('Destroying ' + sessions.length + ' expired sessions.');
                        for (var i in sessions)
                        {
                            sessions[i].destroy();
                        }
                    }
                })