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", "author": "Calvin Montgomery",
"name": "CyTube", "name": "CyTube",
"description": "Online media synchronizer and chat", "description": "Online media synchronizer and chat",
"version": "3.74.2", "version": "3.75.0",
"repository": { "repository": {
"url": "http://github.com/calzoneman/sync" "url": "http://github.com/calzoneman/sync"
}, },

View File

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