centrifugal / centrifuge-js

JavaScript client SDK to communicate with Centrifugo and Centrifuge-based server from browser, NodeJS and React Native. Supports WebSocket, HTTP-streaming over Fetch and Readable Stream API, EventSource, WebTransport.
https://centrifugal.dev
MIT License
411 stars 104 forks source link

Already subscribed error , Sometimes client unsubscribe not working . #285

Closed sajjad-fatehi closed 6 months ago

sajjad-fatehi commented 6 months ago

hi . version : centrifuge-js 5.1.1 in this code :

private init(): centrifuge.Subscription {
    const exists = this._centri.getSubscription(this._channel);
    if (exists !== null) return exists;
    try {
      return this._centri.newSubscription(this._channel, {
        getToken: this._channelTokenGenerator,
      });
    } catch (error) {
      if (exists !== null && this._tries <= 3) {
        this._tries++;
        return this.init();
      }
      throw new AppError('newSubscription error', { cause: error });
    }
  }

i have logic for controlling duplicate subscriptions for not throwing errors in duplicate request . and i always unsubscribe client from channel before clean up everything .

  public async close(): Promise<void> {
        this._roomSubscription.unsubscribe();
  }

but sometimes it not working

as you can see after close method the subscription exists but my logic throws error

throw new AppError('newSubscription error', { cause: error });

do you have any situation like this ?

sajjad-fatehi commented 6 months ago

problem was in my code . fixed