NodeBB / NodeBB

Node.js based forum software built for the modern web
https://nodebb.org
GNU General Public License v3.0
14.18k stars 2.79k forks source link

{"error":"Cannot read property '_csrf' of undefined"} #1554

Closed psychobunny closed 10 years ago

psychobunny commented 10 years ago

This error is the first error to happen when your DB connection conks out. Because of that, loading NodeBB in the browser will display this error and not the related connection error.

I guess this happens because Redis error handling is event based now

julianlam commented 10 years ago

when your DB connection conks out.

Oh, I had no idea this was the reason, but it makes complete sense.

Related to these lines of code -- should we:

barisusakli commented 10 years ago

If those lines were printing the error there would be a stacktrace no? I think doing a process exit in there causes the stack traces to disappear.

julianlam commented 10 years ago

They do show up -- the stack trace is output, and then 3 or 4 _csrf-related stack traces show up, and the NodeBB becomes inaccessible.

At least, they do on development mode, not sure about production mode.

frenchja commented 10 years ago

FWIW, when the DB connection dies, the Redis process appears alive and well. For example, right now I can connect to Redis using redis-cli and run redis-benchmark, but NodeBB displays {"error":"Cannot read property '_csrf' of undefined"}.

http://fpaste.org/104601/ http://fpaste.org/104602/ http://fpaste.org/104603/

julianlam commented 10 years ago

@frenchja Yep, that's what I'm seeing as well. It's not Redis itself that's failing, just bad usage of it on our end (possibly due to a plugin?), so the db handler dies, and never gets reconnected.

@barisusakli Could we just do db.init() and call it a day?

frenchja commented 10 years ago

I'll begin selectively disabling plugins to see if it is a specific plugin problem. Any ones I should try first in the experiment?

Kurosar commented 10 years ago

I'm having the same error and i'm only using :

I hope this will help.

julianlam commented 10 years ago

@Sakarias-Longhorn If you could give us a full stack trace (from the file logs/output.log or logs/error.log, that would help diagnose the underlying issue.

@frenchja -- offhand, none of this plugins look suspicious -- possibly imgbed?

Kurosar commented 10 years ago

I think that's what you're searching for :

{"level":"error","message":"TypeError: undefined is not a function\n at Object.Topics.createTags (C:\Users\Administrateur\Documents\GitHub\NodeBB\src\topics\tags.js:13:11)\n at C:\Users\Administrateur\Documents\GitHub\NodeBB\src\topics\tags.js:96:14\n at C:\Users\Administrateur\Documents\GitHub\NodeBB\node_modules\async\lib\async.js:232:13\n at C:\Users\Administrateur\Documents\GitHub\NodeBB\node_modules\async\lib\async.js:119:25\n at C:\Users\Administrateur\Documents\GitHub\NodeBB\node_modules\async\lib\async.js:24:16\n at C:\Users\Administrateur\Documents\GitHub\NodeBB\node_modules\async\lib\async.js:229:17\n at C:\Users\Administrateur\Documents\GitHub\NodeBB\node_modules\async\lib\async.js:516:34\n at try_callback (C:\Users\Administrateur\Documents\GitHub\NodeBB\node_modules\redis\index.js:573:9)\n at RedisClient.return_reply (C:\Users\Administrateur\Documents\GitHub\NodeBB\node_modules\redis\index.js:661:13)\n at ReplyParser. (C:\Users\Administrateur\Documents\GitHub\NodeBB\node_modules\redis\index.js:309:14)","timestamp":"2014-05-24T23:45:50.074Z"}

barisusakli commented 10 years ago

Fixed in https://github.com/NodeBB/NodeBB/commit/9079d7f26f0ab94c833febf3f40ac707d99fe3c3 thanks for reporting @Sakarias-Longhorn

dusinnhht commented 10 years ago

Hi! I'm getting the same error ({ "error": "Cannot read property '_csrf' of undefined"}) , but right after giving in my email/password. Then I have to restart NodeBB to get the forum to work. When I see the error, the URL is http://192.168.1.120:4567/?loggedin. In the logs/errors.log: {"level":"error","message":"Error: ERR unknown command 'pexpire'
at ReplyParser. (/home/dusi/nodebb2/node_modules/redis/index.js:305:31)\ at ReplyParser.EventEmitter.emit (events.js:95:17)
at ReplyParser.send_error (/home/dusi/nodebb2/node_modules/redis/lib/parser/javascript.js:296:10)
at ReplyParser.execute (/home/dusi/nodebb2/node_modules/redis/lib/parser/javascript.js:181:22) at RedisClient.on_data (/home/dusi/nodebb2/node_modules/redis/index.js:534:27) at Socket. (/home/dusi/nodebb2/node_modules/redis/index.js:91:14)
at Socket.EventEmitter.emit (events.js:95:17) at Socket. (_streamreadable.js:745:14) at Socket.EventEmitter.emit (events.js:92:17) at emitReadable (_stream_readable.js:407:10)","timestamp":"2014-05-25T19:55:11.754Z"}

julianlam commented 10 years ago

Hey there, sounds like your Redis is out of date. You need a minimum of redis 2.6 for NodeBB :-)

dusinnhht commented 10 years ago

Thanks for the info, its working fine now. :)

julianlam commented 10 years ago

From what I could find, this error is caused not by our database handler, but by connect-redis, which elects to not automatically reconnect when an error is encountered, but just blindly sets req.session to null with absolutely no error logging.

My attempts to restart the redis sessionStore from the redis error callback were unsuccessful, so NodeBB will crash with error code 1, which is caught by the loader, and should bring NodeBB back up again.

julianlam commented 10 years ago

Related upstream issue: visionmedia/connect-redis#95, but even if merged, would only add more verbose error messages, and not resolve the problem.