Commit 2ada27de authored by nanahira's avatar nanahira

add timeout

parent b70ecdb5
Pipeline #20896 failed with stages
in 1 minute and 36 seconds
This diff is collapsed.
......@@ -18,11 +18,12 @@
"@types/cron": "^1.7.2",
"@types/q": "^1.5.4",
"@types/yaml": "^1.9.7",
"axios": "^0.19.2",
"axios": "^1.3.4",
"delay": "^5.0.0",
"icmp": "^2.0.1",
"lodash": "^4.17.21",
"p-queue": "6.6.2",
"p-timeout": "4.1.0",
"q": "^1.5.1",
"yaml": "^1.10.0"
},
......
......@@ -9,6 +9,7 @@ import { ping } from 'icmp';
import delay from 'delay';
import PQueue from 'p-queue';
import https from 'https';
import pTimeout from 'p-timeout';
interface Source {
protocol: string;
......@@ -280,7 +281,7 @@ class Checker {
const socket = new net.Socket();
socket.connect(port, address);
socket.setTimeout(this.config.timeout || 1000);
socket.setTimeout(this.config.timeout);
socket.on('connect', () => {
socket.destroy();
......@@ -463,11 +464,18 @@ class Checker {
);
let lastResult: ConnectResult;
for (let i = 1; i <= this.config.retryCount; ++i) {
const result = await checkMethodFunction(source, address);
if (result == ConnectResult.Good) {
return result;
const prom = checkMethodFunction(source, address);
try {
lastResult = await pTimeout(prom, this.config.timeout * 2 + 1000);
} catch (e) {
this.message(
`Connection ${this.getSourcePattern(source, address)} timeout.`,
);
lastResult = ConnectResult.CDNBad;
}
if (lastResult == ConnectResult.Good) {
return lastResult;
}
lastResult = result;
}
if (lastResult === ConnectResult.CDNBad) {
this.message(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment