Skip to content

Commit

Permalink
Do not send subscribe frames during disconnect based only on _transpo…
Browse files Browse the repository at this point in the history
…rtIsOpen flag
  • Loading branch information
ThisIsEsh committed Apr 5, 2024
1 parent 9b325e0 commit 1e35d23
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/centrifuge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,9 @@ export class Centrifuge extends (EventEmitter as new () => TypedEventEmitter<Cli
if (this._isDisconnected()) {
return;
}

// we mark transport is closed right away, because _clearConnectedState will move subscriptions to subscribing state
// if transport will still be open at this time, subscribe frames will be sent to closing transport
this._transportIsOpen = false;
const previousState = this.state;

const ctx = {
Expand Down Expand Up @@ -1248,7 +1250,6 @@ export class Centrifuge extends (EventEmitter as new () => TypedEventEmitter<Cli
transport.close(); // Close only after setting this._transport to null to avoid recursion when calling transport close().
// Need to mark as closed here, because connect call may be sync called after disconnect,
// transport onClose callback will not be called yet
this._transportIsOpen = false;
this._transportClosed = true;
this._nextTransportId();
} else {
Expand Down
4 changes: 1 addition & 3 deletions src/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,7 @@ export class Subscription extends (EventEmitter as new () => TypedEventEmitter<S
if (this._setState(SubscriptionState.Subscribing)) {
this.emit('subscribing', { channel: this.channel, code: code, reason: reason });
}
if (code === subscribingCodes.subscribeCalled) {
this._subscribe();
}
this._subscribe();
}

private _subscribe(): any {
Expand Down

0 comments on commit 1e35d23

Please sign in to comment.