armenfilipetyan / express-session-rethinkdb

RethinkDB session store for Express 4.x
MIT License
25 stars 12 forks source link

ReqlDriverError: `run` was called without a connection and no pool has been created after: #6

Open bkolobara opened 9 years ago

bkolobara commented 9 years ago

I'm getting this error on each request and can't figure out what is breaking. I double checked the database configuration and everything looks right.

Here is the full stack trace:

ReqlDriverError: `run` was called without a connection and no pool has been created after:
r.table("sessions").insert({
    id: "MaRN8Awpa4L3QI9PikJQLmEijNaf_ti9",
    expires: 1441460974366,
    session: "{"cookie":{"originalMaxAge":860000,"expires":"2015-09-05T13:49:34.365Z","httpOnly":true,"path":"/"}}"
}, {
    conflict: "replace"
})
    at Term.run (/Users/bkolobara/Development/scbo_server/node_modules/express-session-rethinkdb/node_modules/rethinkdbdash/lib/term.js:127:19)
    at Store.RethinkStore.set (/Users/bkolobara/Development/scbo_server/node_modules/express-session-rethinkdb/lib/express-session-rethinkdb.js:50:73)
    at Session.save (/Users/bkolobara/Development/scbo_server/node_modules/express-session/session/session.js:71:25)
    at Session.save (/Users/bkolobara/Development/scbo_server/node_modules/express-session/index.js:327:15)
    at ServerResponse.end (/Users/bkolobara/Development/scbo_server/node_modules/express-session/index.js:285:21)
    at ServerResponse.send (/Users/bkolobara/Development/scbo_server/node_modules/express/lib/response.js:204:10)
    at /Users/bkolobara/Development/scbo_server/index.js:37:7
    at Layer.handle [as handle_request] (/Users/bkolobara/Development/scbo_server/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/bkolobara/Development/scbo_server/node_modules/express/lib/router/route.js:131:13)
    at Route.dispatch (/Users/bkolobara/Development/scbo_server/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/Users/bkolobara/Development/scbo_server/node_modules/express/lib/router/layer.js:95:5)
    at /Users/bkolobara/Development/scbo_server/node_modules/express/lib/router/index.js:277:22
    at Function.process_params (/Users/bkolobara/Development/scbo_server/node_modules/express/lib/router/index.js:330:12)
    at next (/Users/bkolobara/Development/scbo_server/node_modules/express/lib/router/index.js:271:10)
    at SendStream.error (/Users/bkolobara/Development/scbo_server/node_modules/express/node_modules/serve-static/index.js:120:7)
    at SendStream.emit (events.js:107:17)```
armenfilipetyan commented 9 years ago

Looks like the ReQL driver cannot connect to the server. Check to make sure you have access to the server with the appropriate port configuration.

bkolobara commented 9 years ago

The whole setup is really simple. I run the server locally. Because of this I'm not sure what could be failing. This is the config:

var express = require('express');
var session = require('express-session');
var RDBStore = require('express-session-rethinkdb')(session);

var rDBStore = new RDBStore({
  connectOptions: {
    servers: [
      { host: '127.0.0.1', port: 28015 }
    ],
    db: 'sc',
    discovery: false,
    pool: false,
    buffer: 50,
    max: 1000,
    timeout: 20,
    timeoutError: 1000
  },
  table: 'sessions',
  sessionTimeout: 1296000000,
  flushInterval: 3600000
});

var app = express();
app.use( require('cookie-parser')() );
app.use( session({
    key: "sid",
    secret: "xxxxxxxxxxxxxxxxx",
    cookie: { maxAge: 860000 },
    store: rDBStore,
    resave: false,
    saveUninitialized: true
  })
);
armenfilipetyan commented 9 years ago

Looks right. But this issue is a ReQL driver issue, not really a express-session-rethinkdb specific issue as it has to deal with the connection itself. Is there an authKey set on the database?

bkolobara commented 9 years ago

No authKey. Something like:

r = require('rethinkdb');
r.connect({ host: '127.0.0.1', port: 28015 }, function(err, conn) { ... });

works fine. That's why I was assuming it's an express-session-rethinkd issue.

bkolobara commented 9 years ago

I'm not sure how I would increase the verbosity to see what is actually failing. I switched to https://github.com/llambda/session-rethinkdb and it is working fine. So I guess it's something express-session-rethinkdb specific.

armenfilipetyan commented 9 years ago

The code to establish a connection itself is pretty simple:

var rethinkdb = require('rethinkdbdash');
r = new rethinkdb(options.connectOptions);

Version 0.2.0 of express-session-rethinkdb should point to the latest version of rethinkdbdash ( 2.1.6 - atm ). Please double check the version of rethinkdbdash in the express-session-rethinkdb dependency tree. Also put some console.log calls after the connection to give it some verbosity.

bkolobara commented 9 years ago

It looks like this code is never called. If I try it manually without rethinkdb running it throws an exception (not able to connect), but if I try to run express-session-rethinkdb it doesn't throw anything.

express-session-rethinkdb@0.2.0 rethinkdbdash@2.1.8 node.js@4.0.0

ghost commented 9 years ago

I had this same issue. Had to create the session table and turn 'pool' to true.

r.db('databaseName').tableCreate('session');
devlesedi commented 9 years ago

I had the same problem. I had to set 'pool' option to true and now it works.

knownasilya commented 8 years ago

It didn't work for me. I suggest allowing your own rdb driver and/or connection object. Currently this module is very brittle because it uses all * dependencies..

knownasilya commented 8 years ago

If anyone is interested I rewrote it to take a connection object with the official driver https://github.com/armenfilipetyan/express-session-rethinkdb/pull/7 If there is interest I can publish to npm.