Trying to reduce cannot call write errors
This commit is contained in:
parent
21f4a5a51a
commit
82ab3f672f
1 changed files with 14 additions and 4 deletions
|
@ -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));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue