mirror of
https://github.com/bitinflow/server.git
synced 2026-03-13 13:35:53 +00:00
better handling of requests that die
This commit is contained in:
6
proxy.js
6
proxy.js
@@ -139,8 +139,14 @@ Proxy.prototype.next_socket = function(cb) {
|
|||||||
return self.waiting.push(cb);
|
return self.waiting.push(cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var done_called = false;
|
||||||
// put the socket back
|
// put the socket back
|
||||||
function done() {
|
function done() {
|
||||||
|
if (done_called) {
|
||||||
|
throw new Error('done called multiple times');
|
||||||
|
}
|
||||||
|
|
||||||
|
done_called = true;
|
||||||
if (!sock.destroyed) {
|
if (!sock.destroyed) {
|
||||||
debug('retuning socket');
|
debug('retuning socket');
|
||||||
self.sockets.push(sock);
|
self.sockets.push(sock);
|
||||||
|
|||||||
13
server.js
13
server.js
@@ -49,6 +49,8 @@ function maybe_bounce(req, res, bounce) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// flag if we already finished before we get a socket
|
||||||
|
// we can't respond to these requests
|
||||||
var finished = false;
|
var finished = false;
|
||||||
on_finished(res, function(err) {
|
on_finished(res, function(err) {
|
||||||
finished = true;
|
finished = true;
|
||||||
@@ -63,6 +65,7 @@ function maybe_bounce(req, res, bounce) {
|
|||||||
if (finished) {
|
if (finished) {
|
||||||
return done();
|
return done();
|
||||||
}
|
}
|
||||||
|
|
||||||
// happens when client upstream is disconnected
|
// happens when client upstream is disconnected
|
||||||
// we gracefully inform the user and kill their conn
|
// we gracefully inform the user and kill their conn
|
||||||
// without this, the browser will leave some connections open
|
// without this, the browser will leave some connections open
|
||||||
@@ -79,12 +82,22 @@ function maybe_bounce(req, res, bounce) {
|
|||||||
|
|
||||||
stream.on('error', function(err) {
|
stream.on('error', function(err) {
|
||||||
socket.destroy();
|
socket.destroy();
|
||||||
|
req.connection.destroy();
|
||||||
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
// return the socket to the client pool
|
// return the socket to the client pool
|
||||||
stream.once('end', function() {
|
stream.once('end', function() {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
on_finished(res, function(err) {
|
||||||
|
if (err) {
|
||||||
|
req.connection.destroy();
|
||||||
|
socket.destroy();
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user