Close websocket if request times out

Co-authored-by: trevor-signal <131492920+trevor-signal@users.noreply.github.com>
This commit is contained in:
automated-signal 2024-04-18 12:36:25 -05:00 committed by GitHub
parent 994811c366
commit f984e55d2c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -656,13 +656,10 @@ export default class WebSocketResource
strictAssert(!this.shuttingDown, 'Cannot send request, shutting down');
this.addActive(idString);
const promise = new Promise<SendRequestResult>((resolve, reject) => {
const sentAt = Date.now();
let timedOut = false;
let timer = options.timeout
? Timers.setTimeout(() => {
timedOut = true;
this.removeActive(idString);
this.close(3001, 'Request timed out');
reject(new Error(`Request timed out; id: [${idString}]`));
}, options.timeout)
: undefined;
@ -672,16 +669,8 @@ export default class WebSocketResource
Timers.clearTimeout(timer);
timer = undefined;
}
if (timedOut) {
log.warn(
`${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.keepalive?.reset();
this.removeActive(idString);
resolve(result);
});