Skip to content

Commit

Permalink
fix: attempt to avoid socket leak in node >= 13.x
Browse files Browse the repository at this point in the history
The default timeout was removed from the HTTP module in node 13.x:
nodejs/node#27558.  I believe this is the most
likely cause of fd leaks when running under current node versions.
  • Loading branch information
calzoneman committed Jan 16, 2021
1 parent 00e9acb commit a75917d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
42 changes: 17 additions & 25 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -197,13 +196,6 @@ var Server = function () {
process.exit(1);
}
});
self.servers[id].on("clientError", function (err, socket) {
try {
socket.destroy();
} catch (e) {
// Ignore
}
});
}
});

Expand Down

0 comments on commit a75917d

Please sign in to comment.