Skip to content

Commit 454df12

Browse files
authored
Merge pull request #544 from keymanapp/feat/service-state
fix: handle https timeout by rejecting the promise
2 parents 716a736 + 3c9b225 commit 454df12

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

server/util/DataChangeTimingManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class DataChangeTimingManager {
1414

1515
if (this.started[id] || lastRunDelta < minInterval) {
1616
if(this.started[id]) {
17-
consoleLog('timing', id, `Data change is still underway (started at ${this.formatDate(this.started[id])}); waiting ${minInterval} milliseconds`);
17+
consoleLog('timing', id, `Data change has been underway for ${(new Date()).valueOf() - this.started[id].valueOf()} msec (started at ${this.formatDate(this.started[id])}); waiting ${minInterval} milliseconds`);
1818
} else {
1919
consoleLog('timing', id, `Data change was only ${lastRunDelta} msec ago (finished at ${this.formatDate(this.lastRun[id])}); waiting ${minInterval} milliseconds`);
2020
}

server/util/httppost.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,22 @@ export default function httppost(hostname, path, headers, data) {
2424
const req = https.request(options, res => {
2525
if(res.statusCode != 200) {
2626
consoleError('http-post', hostname, `statusCode for ${hostname}${path}: ${res.statusCode} ${res.statusMessage}`);
27+
if(timeoutId) {
28+
clearTimeout(timeoutId);
29+
}
2730
reject(`statusCode for ${hostname}${path}: ${res.statusCode} ${res.statusMessage}`);
2831
return;
2932
}
3033

3134
res.on('data', d => {
3235
chunk += d;
33-
});
36+
});
3437

3538
res.on('end', () => {
3639
//console.log(chunk);
40+
if(timeoutId) {
41+
clearTimeout(timeoutId);
42+
}
3743
resolve(chunk);
3844
});
3945
});
@@ -43,10 +49,16 @@ export default function httppost(hostname, path, headers, data) {
4349
reject(error);
4450
});
4551

46-
req.setTimeout(180000, () => {
52+
const timeoutId = setTimeout(() => {
4753
consoleError('http-post', hostname, `timeout after 3 minutes on ${hostname}${path}`);
48-
req.destroy();
49-
})
54+
req?.destroy();
55+
reject(`timeout after 3 minutes on ${hostname}${path}`);
56+
}, 180000);
57+
58+
// req.setTimeout(180000, () => {
59+
// consoleError('http-post', hostname, `timeout after 3 minutes on ${hostname}${path}`);
60+
// req.destroy();
61+
// })
5062

5163
req.write(data);
5264
req.end();

0 commit comments

Comments
 (0)