Skip to content

Commit

Permalink
prevent memory leaking on uncompleted requests & add max post size li…
Browse files Browse the repository at this point in the history
…mitation
  • Loading branch information
3rd-Eden committed Nov 23, 2011
1 parent 7948619 commit a7f45fe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/manager.js
Expand Up @@ -78,6 +78,7 @@ function Manager (server, options) {
, 'flash policy server': true
, 'flash policy port': 10843
, 'destroy upgrade': true
, 'destroy buffer size': 10E7
, 'browser client': true
, 'browser client cache': true
, 'browser client minification': false
Expand Down Expand Up @@ -625,7 +626,7 @@ Manager.prototype.handleClient = function (data, req) {

var transport = new transports[data.transport](this, data, req)
, handshaken = this.handshaken[data.id];

if (transport.disconnected) {
// failed during transport setup
req.connection.end();
Expand Down Expand Up @@ -778,12 +779,12 @@ Manager.prototype.handshakeData = function (data) {
connectionAddress = {
address: connection.remoteAddress
, port: connection.remotePort
};
};
} else if (connection.socket && connection.socket.remoteAddress) {
connectionAddress = {
address: connection.socket.remoteAddress
, port: connection.socket.remotePort
};
};
}

return {
Expand Down Expand Up @@ -829,7 +830,7 @@ Manager.prototype.verifyOrigin = function (request) {
}
}
else {
this.log.warn('origin missing from handshake, yet required by config');
this.log.warn('origin missing from handshake, yet required by config');
}
return false;
};
Expand Down
10 changes: 10 additions & 0 deletions lib/transports/http.js
Expand Up @@ -51,6 +51,11 @@ HTTPTransport.prototype.handleRequest = function (req) {

req.on('data', function (data) {
buffer += data;

if (Buffer.byteLength(buffer) >= self.manager.get('destroy buffer size')) {
buffer = '';
req.connection.destroy();
}
});

req.on('end', function () {
Expand All @@ -60,6 +65,11 @@ HTTPTransport.prototype.handleRequest = function (req) {
self.onData(self.postEncoded ? qs.parse(buffer).d : buffer);
});

// prevent memory leaks for uncompleted requests
req.on('close', function () {
buffer = '';
});

if (origin) {
// https://developer.mozilla.org/En/HTTP_Access_Control
headers['Access-Control-Allow-Origin'] = '*';
Expand Down

0 comments on commit a7f45fe

Please sign in to comment.