Skip to content

Commit

Permalink
Close websocket if request times out
Browse files Browse the repository at this point in the history
  • Loading branch information
trevor-signal committed Apr 18, 2024
1 parent 187fe08 commit d31a4d5
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions ts/textsecure/WebsocketResources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
});
Expand Down

0 comments on commit d31a4d5

Please sign in to comment.