Time out idle connections.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3896 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2022-06-07 02:08:06 +00:00
parent ae894eaa9d
commit 1dc6084d2d

View File

@ -358,10 +358,12 @@ function badRequest(client, reason) {
gBadRequests[client.peerName] = {
expire: new Date(now.getTime() + 10 * 60 * 1000),
count: 1,
reason: reason,
};
count = 1;
} else {
old.count++;
old.reason = reason;
count = old.count;
}
new Response({version: '1.0'}, client).reportError(reason + ': ' + count);
@ -385,7 +387,7 @@ function allowRequest(client) {
function handleConnection(client) {
if (!allowRequest(client)) {
print('Rejecting client for too many bad requests: ', client.peerName);
print('Rejecting client for too many bad requests: ', client.peerName, gBadRequests[client.peerName].reason);
client.close();
return;
}
@ -401,7 +403,11 @@ function handleConnection(client) {
function resetTimeout(requestIndex) {
setTimeout(function() {
if (bodyToRead == -1 && requestCount == requestIndex) {
badRequest(client, 'Timed out waiting for request.');
if (requestCount == 0) {
badRequest(client, 'Timed out waiting for request.');
} else {
client.close();
}
}
}, kRequestTimeout);
}
@ -470,6 +476,8 @@ function handleConnection(client) {
var requestObject = new Request(request[0], request[1], request[2], headers, body, client);
var response = new Response(requestObject, client);
handleWebSocketRequest(requestObject, response, client);
/* Prevent the timeout from disconnecting us. */
requestCount++;
return false;
} else {
finish();