Cleanup rogue timeout in TS client (#1653)
This commit is contained in:
parent
473e578efc
commit
b91499b2fc
|
|
@ -683,6 +683,33 @@ describe("HubConnection", () => {
|
|||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it("does not timeout if message was received before HubConnection.start", async () => {
|
||||
const connection = new TestConnection();
|
||||
const hubConnection = new HubConnection(connection, { ...commonOptions, timeoutInMilliseconds: 100 });
|
||||
|
||||
const p = new PromiseSource<Error>();
|
||||
hubConnection.onclose((e) => p.resolve(e));
|
||||
|
||||
// send message before start to trigger timeout handler
|
||||
// testing for regression where we didn't cleanup timer if request received before start created a timer
|
||||
await connection.receive({ type: MessageType.Ping });
|
||||
|
||||
await hubConnection.start();
|
||||
|
||||
await connection.receive({ type: MessageType.Ping });
|
||||
await delay(50);
|
||||
await connection.receive({ type: MessageType.Ping });
|
||||
await delay(50);
|
||||
await connection.receive({ type: MessageType.Ping });
|
||||
await delay(50);
|
||||
|
||||
connection.stop();
|
||||
|
||||
const error = await p.promise;
|
||||
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it("terminates if no messages received within timeout interval", async () => {
|
||||
const connection = new TestConnection();
|
||||
const hubConnection = new HubConnection(connection, { ...commonOptions, timeoutInMilliseconds: 100 });
|
||||
|
|
|
|||
|
|
@ -60,9 +60,7 @@ export class HubConnection {
|
|||
}
|
||||
|
||||
private processIncomingData(data: any) {
|
||||
if (this.timeoutHandle !== undefined) {
|
||||
clearTimeout(this.timeoutHandle);
|
||||
}
|
||||
this.cleanupTimeout();
|
||||
|
||||
if (!this.receivedHandshakeResponse) {
|
||||
data = this.processHandshakeResponse(data);
|
||||
|
|
@ -196,9 +194,9 @@ export class HubConnection {
|
|||
});
|
||||
this.callbacks.clear();
|
||||
|
||||
this.closedCallbacks.forEach((c) => c.apply(this, [error]));
|
||||
|
||||
this.cleanupTimeout();
|
||||
|
||||
this.closedCallbacks.forEach((c) => c.apply(this, [error]));
|
||||
}
|
||||
|
||||
public async start(): Promise<void> {
|
||||
|
|
@ -213,6 +211,8 @@ export class HubConnection {
|
|||
|
||||
this.logger.log(LogLevel.Information, `Using HubProtocol '${this.protocol.name}'.`);
|
||||
|
||||
// defensively cleanup timeout in case we receive a message from the server before we finish start
|
||||
this.cleanupTimeout();
|
||||
this.configureTimeout();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue