mirror of
https://github.com/kopia/kopia.git
synced 2026-10-28 17:20:03 -04:00
fix(kopiaui): ensure timing out status poll requests, only perform one request at a time to avoid exhausting sockets (#5650)
This commit is contained in:
1 parent
5d3d878117
commit
e2005f8dec
1 file changed
+19
@@ -73,6 +73,8 @@ function newServerForRepo(repoID) {
|
||||
|
||||
const pollInterval = 3000;
|
||||
|
||||
let statusPollInProgress = false;
|
||||
|
||||
function pollOnce() {
|
||||
if (
|
||||
!runningServerAddress ||
|
||||
@@ -83,6 +85,14 @@ function newServerForRepo(repoID) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Wait for previous poll request. If the request hangs, it will time out
|
||||
// eventually and sockets shouldn't be exhausted by trying all the time.
|
||||
if (statusPollInProgress) {
|
||||
return;
|
||||
}
|
||||
|
||||
statusPollInProgress = true;
|
||||
|
||||
const req = https.request(
|
||||
{
|
||||
ca: [runningServerCertificate],
|
||||
@@ -117,12 +127,21 @@ function newServerForRepo(repoID) {
|
||||
});
|
||||
} else {
|
||||
log.warn("error fetching status", resp.statusMessage);
|
||||
resp.resume();
|
||||
}
|
||||
},
|
||||
);
|
||||
req.on("timeout", () => {
|
||||
req.destroy(
|
||||
new Error(`status request timed out after ${pollInterval}ms`),
|
||||
);
|
||||
});
|
||||
req.on("error", (e) => {
|
||||
log.info("error fetching status", e);
|
||||
});
|
||||
req.on("close", () => {
|
||||
statusPollInProgress = false;
|
||||
});
|
||||
req.end();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user