fix: attempt to avoid socket leak in node >= 13.x

The default timeout was removed from the HTTP module in node 13.x:
https://github.com/nodejs/node/pull/27558.  I believe this is the most
likely cause of fd leaks when running under current node versions.
This commit is contained in:
Calvin Montgomery 2021-01-16 14:19:22 -08:00
parent 00e9acbe4d
commit a75917d4e4
2 changed files with 18 additions and 26 deletions

View file

@ -2,7 +2,7 @@
"author": "Calvin Montgomery",
"name": "CyTube",
"description": "Online media synchronizer and chat",
"version": "3.74.2",
"version": "3.75.0",
"repository": {
"url": "http://github.com/calzoneman/sync"
},

View file

@ -29,14 +29,15 @@ module.exports = {
}
};
var path = require("path");
var fs = require("fs");
var https = require("https");
var express = require("express");
var Channel = require("./channel/channel");
var db = require("./database");
var Flags = require("./flags");
var sio = require("socket.io");
const path = require("path");
const fs = require("fs");
const http = require("http");
const https = require("https");
const express = require("express");
const Channel = require("./channel/channel");
const db = require("./database");
const Flags = require("./flags");
const sio = require("socket.io");
import LocalChannelIndex from './web/localchannelindex';
import { PartitionChannelIndex } from './partition/partitionchannelindex';
import IOConfiguration from './configuration/ioconfig';
@ -162,8 +163,10 @@ var Server = function () {
}
if (bind.https && Config.get("https.enabled")) {
self.servers[id] = https.createServer(opts, self.express)
.listen(bind.port, bind.ip);
self.servers[id] = https.createServer(opts, self.express);
// 2 minute default copied from node <= 12.x
self.servers[id].timeout = 120000;
self.servers[id].listen(bind.port, bind.ip);
self.servers[id].on("error", error => {
if (error.code === "EADDRINUSE") {
LOGGER.fatal(
@ -176,15 +179,11 @@ var Server = function () {
process.exit(1);
}
});
self.servers[id].on("clientError", function (err, socket) {
try {
socket.destroy();
} catch (e) {
// Ignore
}
});
} else if (bind.http) {
self.servers[id] = self.express.listen(bind.port, bind.ip);
self.servers[id] = http.createServer(self.express);
// 2 minute default copied from node <= 12.x
self.servers[id].timeout = 120000;
self.servers[id].listen(bind.port, bind.ip);
self.servers[id].on("error", error => {
if (error.code === "EADDRINUSE") {
LOGGER.fatal(
@ -197,13 +196,6 @@ var Server = function () {
process.exit(1);
}
});
self.servers[id].on("clientError", function (err, socket) {
try {
socket.destroy();
} catch (e) {
// Ignore
}
});
}
});