Here is a terrible bug in nStore. When used together with express, and nstore-session it somehow manages to create a wrong index for the database, which leads to invalid JSON exceptions being thrown.
Here is an example. This database was created by nstore-session:
And when used, nStore would throw the following error:
SyntaxError: Unexpected token ILLEGAL
at Object.parse (native)
at /usr/local/pkg/nodejs-0.2.0/lib/node/.npm/nStore/0.2.1/package/lib/nstore.js:103:27
at /usr/local/pkg/nodejs-0.2.0/lib/node/.npm/nStore/0.2.1/package/lib/nstore.js:33:7
at node.js:764:9
So I debugged it and located that when it requests the last key 'dccae3e52ec5ef3f584aea9df1bb.6f58e178ddc813ae35b84c665a58ec8b', the index it uses to read the record from the db file is messed up:
Next run node ./stackvm/bin/populate.js to populate users database.
Then run node ./stackvm/server.js to start StackVM locally.
Then connect to localhost:9000 and use pkrumins as login and moo as password. That will log you into StackVM.
Now in the console you should see SyntaxError: Unexpected token ILLEGAL. Also if you now press logout, express will catch this exception and display it in the browser. But you'll also see it in the console.
I hope you can locate this bug, I spent a lot of time debugging it but could not determine what caused it. If you just simply took the database I listed there above (and replace 4 spaces between records with tabs), it would work. Doesn't work just in the web environment.
Here is a terrible bug in nStore. When used together with express, and nstore-session it somehow manages to create a wrong index for the database, which leads to invalid JSON exceptions being thrown.
Here is an example. This database was created by nstore-session:
And when used, nStore would throw the following error:
So I debugged it and located that when it requests the last key 'dccae3e52ec5ef3f584aea9df1bb.6f58e178ddc813ae35b84c665a58ec8b', the index it uses to read the record from the db file is messed up:
The contents in the db at position 279 is:
At line 101 nStore tries to call
JSON.parse(buffer.toString());
and thisbuffer.toString()
is the data above. So it throws an exception that I listed.Here is how to reproduce. Clone StackVM at this revision: http://github.com/substack/stackvm/commit/fa702d45234532b7bacc572e08676f4b74627cd0
Next run
node ./stackvm/bin/populate.js
to populate users database.Then run
node ./stackvm/server.js
to start StackVM locally.Then connect to localhost:9000 and use
pkrumins
as login andmoo
as password. That will log you into StackVM.Now in the console you should see
SyntaxError: Unexpected token ILLEGAL
. Also if you now presslogout
, express will catch this exception and display it in the browser. But you'll also see it in the console.I hope you can locate this bug, I spent a lot of time debugging it but could not determine what caused it. If you just simply took the database I listed there above (and replace 4 spaces between records with tabs), it would work. Doesn't work just in the web environment.