Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConnectionManager: Fix uprade bug that could lead to an indefinitely sync-pending transport #1041

Merged
merged 1 commit into from
Aug 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/common/lib/transport/connectionmanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,11 +582,12 @@ class ConnectionManager extends EventEmitter {
connectionDetails: Record<string, any>,
connectionPosition: ConnectionManager
) => {
if (mode == 'upgrade' && this.activeProtocol) {
if (mode == 'upgrade') {
/* if ws and xhrs are connecting in parallel, delay xhrs activation to let ws go ahead */
if (
transport.shortName !== optimalTransport &&
Utils.arrIn(this.getUpgradePossibilities(), optimalTransport)
Utils.arrIn(this.getUpgradePossibilities(), optimalTransport) &&
this.activeProtocol
) {
setTimeout(() => {
this.scheduleTransportActivation(error, transport, connectionId, connectionDetails, connectionPosition);
Expand Down Expand Up @@ -678,7 +679,7 @@ class ConnectionManager extends EventEmitter {
'Scheduling transport upgrade; transport = ' + transport
);

this.realtime.channels.onceNopending((err: ErrorInfo) => {
const onReadyToUpgrade = (err?: ErrorInfo) => {
let oldProtocol: Protocol | null;
if (err) {
Logger.logAction(
Expand Down Expand Up @@ -822,7 +823,15 @@ class ConnectionManager extends EventEmitter {
}
}
);
});
};

// No point waiting for pending attaches if there's no active transport, just sync and
// activate the new one immediately, attaches will be retried on the new one
if (currentTransport) {
this.realtime.channels.onceNopending(onReadyToUpgrade);
} else {
onReadyToUpgrade();
}
}

/**
Expand Down