Skip to content

Commit

Permalink
End pending connections on close after responses are written
Browse files Browse the repository at this point in the history
  • Loading branch information
Subbu Allamaraju committed Apr 27, 2012
1 parent 4587f6d commit 4ba4f39
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
@@ -1,3 +1,7 @@
## Apr 27, 2012

* End pending connections on close after responses are written.

## Apr 26, 2012

* Switch to new cluster2
Expand Down
9 changes: 9 additions & 0 deletions modules/compiler/test/select-test.js
Expand Up @@ -950,5 +950,14 @@ module.exports = {
test.equals(select.columns[0].name, "a[\"b\"]");
test.equals(cooked[0].route.path.value, '/a');
test.done();
},

'select-join-return-deps': function(test) {
var q = 'master = select * from table.master where query = "iPad" limit 10;\
details = select * from table.details where id in ("{master.id}");\
return select m.id, m.title, d.text from master as m, details as d where m.id = d.id;';
var cooked = compiler.compile(q);
console.log(cooked);
test.done();
}
};
18 changes: 17 additions & 1 deletion modules/console/app.js
Expand Up @@ -51,6 +51,14 @@ var Console = module.exports = function(config, cb) {

var app = this.app = express.createServer();

// Remains true until the app receives a 'close' event. Once this event is received, the app
// sends 'connection: close' on responses (except for express served responses) and ends
// the connection. See the app.on('close') handler below.
var serving;
app.on('listening', function() {
serving = true;
});

app.enable('case sensitive routes'); // Default routes are not case sensitive

// Add parser for xml
Expand Down Expand Up @@ -622,6 +630,7 @@ var Console = module.exports = function(config, cb) {
// Let the Engine cleanup during shutdown
app.on('close', function() {
clearInterval(heartbeat);
serving = false;
});

// Also listen to WebSocket requests
Expand Down Expand Up @@ -690,6 +699,9 @@ var Console = module.exports = function(config, cb) {
data: results
}));
}
if(!serving) {
connection.end();
}
})
})
}
Expand Down Expand Up @@ -777,7 +789,7 @@ var Console = module.exports = function(config, cb) {
res._header = undefined;
var contentType = results.headers['content-type'];
var h = {
'Connection': 'keep-alive',
'Connection': serving ? 'keep-alive' : 'close',
'Transfer-Encoding' : 'chunked'
};
_.each(results.headers, function(value, name) {
Expand Down Expand Up @@ -808,6 +820,10 @@ var Console = module.exports = function(config, cb) {
}
res.end();
}
// If we get a 'close' event, end on all pending connections.
if(!serving) {
req.connection.end();
}
}

// The caller gets the app and the engine/event emitter
Expand Down
2 changes: 1 addition & 1 deletion modules/console/package.json
@@ -1,7 +1,7 @@
{
"author": "ql.io",
"name": "ql.io-console",
"version": "0.5.6",
"version": "0.5.7",
"repository": {
"type": "git",
"url": "https://github.com/ql-io/ql.io"
Expand Down

0 comments on commit 4ba4f39

Please sign in to comment.