Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require Cluster2 causes express application to not work properly #43

Open
lagoasoft-lucasschmidt opened this issue May 11, 2013 · 0 comments

Comments

@lagoasoft-lucasschmidt
Copy link

I added a sample code below. If you run this express application, and open two browsers at the same time (getting 2 different sessions), and start running concurrent requests, you will see that all requests will receive the same response.locals object (see express/middleware.js). That causes concurrent requests to simply have this weird behavior of having its locals modified by another request, if they do async operations and have to wait.

Notice that I am not even creating a Cluster, I just required the module.

[email protected].*
[email protected]

var Cluster, app, express;

express = require('express');

Cluster = require('cluster2');

app = express();

app.port = process.env.PORT || process.env.VMC_APP_PORT || 3000;

app.configure(function() {
app.use(express.compress());
app.use(express.cookieParser('some secret'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.session({
secret: 'some secret'
}));
app.use(express.csrf());
app.use(function(req, res, next) {
res.locals.csrf = req.session._csrf;
res.locals.userAgent = req.headers['user-agent'];
return next();
});
app.use(app.router);
app.get('/', function(req, res) {
return setTimeout((function() {
if (req.session._csrf !== res.locals.csrf) {
console.log('ERROR, CSRF DOESNT MATCH');
}
return res.json('index');
}), Math.random() * 5000);
});
return module.exports = app;
});

I didnt analyse much Cluster 2 code to see what happens during the require of the module, I just thought I should let you guys know about this strange behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant