Close websocket if request times out
This commit is contained in:
parent
187fe08816
commit
d31a4d5d91
1 changed files with 3 additions and 14 deletions
|
@ -656,13 +656,10 @@ export default class WebSocketResource
|
||||||
strictAssert(!this.shuttingDown, 'Cannot send request, shutting down');
|
strictAssert(!this.shuttingDown, 'Cannot send request, shutting down');
|
||||||
this.addActive(idString);
|
this.addActive(idString);
|
||||||
const promise = new Promise<SendRequestResult>((resolve, reject) => {
|
const promise = new Promise<SendRequestResult>((resolve, reject) => {
|
||||||
const sentAt = Date.now();
|
|
||||||
let timedOut = false;
|
|
||||||
|
|
||||||
let timer = options.timeout
|
let timer = options.timeout
|
||||||
? Timers.setTimeout(() => {
|
? Timers.setTimeout(() => {
|
||||||
timedOut = true;
|
|
||||||
this.removeActive(idString);
|
this.removeActive(idString);
|
||||||
|
this.close(3001, 'Request timed out');
|
||||||
reject(new Error(`Request timed out; id: [${idString}]`));
|
reject(new Error(`Request timed out; id: [${idString}]`));
|
||||||
}, options.timeout)
|
}, options.timeout)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
@ -672,16 +669,8 @@ export default class WebSocketResource
|
||||||
Timers.clearTimeout(timer);
|
Timers.clearTimeout(timer);
|
||||||
timer = undefined;
|
timer = undefined;
|
||||||
}
|
}
|
||||||
if (timedOut) {
|
|
||||||
log.warn(
|
this.keepalive?.reset();
|
||||||
`${this.logId}: Response received after timeout; ` +
|
|
||||||
`id: [${idString}], path: [${options.path}], ` +
|
|
||||||
`response time: ${Date.now() - sentAt}ms`
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
// Reset keepalive when an on-time response arrives
|
|
||||||
this.keepalive?.reset();
|
|
||||||
}
|
|
||||||
this.removeActive(idString);
|
this.removeActive(idString);
|
||||||
resolve(result);
|
resolve(result);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue