Closed
Description
Hey Kai, I think I discovered another bordercase regarding the signalr service generation.
I have enabled autoreconnect as option during generation.
[KY.Generator.GenerateWithRetry(true, 100, 100, 1000, 5000)]
On my component I call Connect() which will fail due to the targeting service isn't running.
In this case, the signalR service correctly tries to reconnect for infinite times.
Now if I call the Disconnect() method, the service keeps trying to reestablish a connection.
this.isClosed = false;
this.connection = this.connection ? this.connection : new ReplaySubject<HubConnection>(1);
let hubConnection: HubConnection = new HubConnectionBuilder().withUrl(this.serviceUrl).build();
let startConnection: () => Observable<void> = () => {
this.statusSubject.next(ConnectionStatus.connecting);
let subject = new Subject<void>();
hubConnection.start().then(() => {
subject.next();
subject.complete();
this.statusSubject.next(ConnectionStatus.connected);
}).catch((error) => {
this.statusSubject.next(ConnectionStatus.disconnected);
let timeout: number = this.timeouts[trial];
trial++;
timeout = timeout || this.timeouts[this.timeouts.length - 1] || 0;
setTimeout(() => startConnection().subscribe(() => {
subject.next();
subject.complete();
}, (innerError) => subject.error(innerError)), timeout);
});
return subject;
};
Probably U should add the IsClosed check to the retry setTimeout handler, to check whether the connection has been already closed by the user?
Possible solution:
}).catch((error) => {
this.statusSubject.next(ConnectionStatus.disconnected);
//----------------------------------------
if (this.isClosed) {
return;
}
//----------------------------------------
let timeout: number = this.timeouts[trial];
trial++;
timeout = timeout || this.timeouts[this.timeouts.length - 1] || 0;
setTimeout(() => startConnection().subscribe(() => {
subject.next();
subject.complete();
}, (innerError) => subject.error(innerError)), timeout);
});