senchalabs/connect — Issue #463: deleted sessionID but browser still has it, and it blows-up
Author: cordoba
Created: 2012-01-23 04:02:55+00:00
State: open

When sessions are stored (with riak in my case), and then deleted from store but browser still has it and then a request is made, server code blows up as following error message shows:

Express
500 Error: undefined
at IncomingMessage. (....../node_modules/riak-js/lib/http_client.js:384:76)
at IncomingMessage.emit (events.js:88:20)
at HTTPParser.onMessageComplete (http.js:137:23)
at Socket.ondata (http.js:1124:24)
at TCP.onread (net.js:348:27)

I temporarily solved it with following provided git diff. However briefly in returned ```session``` function ```store.get``` call results with some ```err``` (correctly reported by persistence store) the code checks ```if ('ENOENT' == err.code) {``` (and for this case it is ```false```) and flow results with ```next(err)```. If ```false``` branch is same as ```true``` branch it works.

index 7224896..f511421 100644
--- a/express/node_modules/connect/lib/middleware/session.js
+++ b/express/node_modules/connect/lib/middleware/session.js
@@ -264,7 +264,8 @@ function session(options){
generate();
next();
} else {
- next(err);
+ generate();
+ next();
}
// no session
} else if (!sess) {