Trying to reduce cannot call write errors

This commit is contained in:
TheEssem 2021-05-17 14:23:29 -05:00
parent 21f4a5a51a
commit 82ab3f672f
No known key found for this signature in database
GPG key ID: A3F9F02129092FCA

View file

@ -93,7 +93,7 @@ exports.connect = (server) => {
} }
}); });
connection.on("error", (e) => { connection.on("error", (e) => {
logger.error(e); logger.error(e.toString());
}); });
connection.once("close", () => { connection.once("close", () => {
for (const uuid of Object.keys(jobs)) { for (const uuid of Object.keys(jobs)) {
@ -129,19 +129,29 @@ const getIdeal = () => {
} }
}, 5000); }, 5000);
for (const connection of this.connections) { for (const connection of this.connections) {
if (!connection.remoteAddress) continue; if (!connection.remoteAddress || connection.destroyed) {
fetch(`http://${connection.remoteAddress}:8081/status`).then(statusRequest => statusRequest.text()).then(async (status) => { serversLeft--;
continue;
}
fetch(`http://${connection.remoteAddress}:8081/status`).then(statusRequest => statusRequest.text()).then((status) => {
serversLeft--; serversLeft--;
idealServers.push({ idealServers.push({
addr: connection.remoteAddress, addr: connection.remoteAddress,
load: parseInt(status) load: parseInt(status)
}); });
return;
}).then(async () => {
if (!serversLeft) { if (!serversLeft) {
clearTimeout(timeout); clearTimeout(timeout);
const server = await chooseServer(idealServers); const server = await chooseServer(idealServers);
resolve(this.connections.find(val => val.remoteAddress === server.addr)); resolve(this.connections.find(val => val.remoteAddress === server.addr));
} }
return; }).catch(e => reject(e));
}
if (!serversLeft) {
clearTimeout(timeout);
chooseServer(idealServers).then(server => {
resolve(this.connections.find(val => val.remoteAddress === server.addr));
}).catch(e => reject(e)); }).catch(e => reject(e));
} }
}); });