senchalabs/connect — Issue #394: Static Range Request Creating Multiple Sessions and Clobbering Cookie
Author: seanabrahams
Created: 2011-10-17 23:58:38+00:00
State: open

I have a GET that stores some data to a session (req.session.token = token) and responds with a page that loads a video (809k) using HTML5's video tag.

The video is served up via static middleware as a range request (status code 206). Interestingly, it appears on each chunk Connect seems to be creating a new session in Redis and clobbering the original cookie in the user's browser.

Since the user's cookie is clobbered with the most recent session key created we no longer have access to the original session data.

Using:

node 0.4.12
├── connect-redis@1.1.0
├─┬ express@2.4.3
│ ├── connect@1.7.1
│ ├── mime@1.2.4
│ └── qs@0.3.1
├─┬ jade@0.16.2
│ ├── commander@0.1.0
│ └── mkdirp@0.0.7
└── redis@0.6.7

app.js

```javascript
/**
* Module dependencies.
*/

var express = require('express'),
redis = require("redis"),
RedisStore = require('connect-redis')(express);

var app = module.exports = express.createServer();

// Configuration

app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser());
app.use(express.session({ secret: "alkjaslkfjslkdfjdf", store: new RedisStore(), key: 'express.sid' }));
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});

app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});

app.configure('production', function(){
app.use(express.errorHandler());
});

// Routes

app.get('/', function(req, res){
res.render('index', {
title: 'Express'
});
});

app.listen(3000);
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
```

index.jade

h1= title
p Welcome to #{title}
video(src="/videos/3.mp4", autoplay="yes", loop="loop", preload="auto", poster="/videos/3.jpg")
source(src="/videos/3.mp4")

HTML output

Express

Express

Welcome to Express

KEYS * in Redis before request:

redis 127.0.0.1:6379> keys *
(empty list or set)

KEYS * in Redis after 1 request:

redis 127.0.0.1:6379> keys *
1) "sess:1at93LcqrZiFAbJDj4Xdgjvk.VxUwdqRxeQDepllW763Q5xzdwWgPiXV3h7W+ktlyLJs"
2) "sess:cbf0k5BjIXgMrNoQWGaPLg2z.HdQxyfsBNAwLKcsirMxlNAGhQGQbGslBAhZB+i3c0vw"
3) "sess:rJHmen3u910vUC5L7HculveC.l++B9kqO35sEUQp79+rKaGl4nLAoNECmnE5TtQ8Ua/I"