From d1de32ea2773df4c6f8a956678bbd19b6d022475 Mon Sep 17 00:00:00 2001 From: Timo <16718859+toger5@users.noreply.github.com> Date: Thu, 12 Dec 2024 15:58:50 +0100 Subject: [PATCH] Only re-prepare MatrixrRTC delayed disconnection event on 404 (#4575) * Set retry counts of event updating to 1000 (from 1) With it being set to one the following issue could occur: ``` // If sending state cancels your own delayed state, prepare another delayed state // TODO: Remove this once MSC4140 is stable & doesn't cancel own delayed state if (this.disconnectDelayId !== undefined) { try { const knownDisconnectDelayId = this.disconnectDelayId; await resendIfRateLimited( () => this.client._unstable_updateDelayedEvent( knownDisconnectDelayId, UpdateDelayedEventAction.Restart, ), 1000, ); } catch (e) { logger.warn("Failed to update delayed disconnection event, prepare it again:", e); this.disconnectDelayId = undefined; await prepareDelayedDisconnection(); } } ``` This code looks like the `catch(e)` could never be triggered with 429 (rate limit) because they would be caught by `await resendIfRateLimited`. EXCEPT that this is only happening once: `resendIfRateLimited(func: () => Promise, numRetriesAllowed: number = 1)`. So as soon as the server sends two rate limits in a row we get the following: - we get into the `catch(e)` because of the rate limit - we forget about `this.disconnectDelayId = undefined` - we start a new delayed event `await prepareDelayedDisconnection();` - we do not anymore update the old delayed event which is still running! - the running delay event will make us disconnect from the call (call member becomes `{}`) - we get into our outher error catching mechanism that resends the new state event - this cancels the newly created delay leave event (`await prepareDelayedDisconnection();`) - and create another delay leave event. - but if we are still reate limited (chances are really high due to the reconnect), this loop will REPEAT * also check for M_NOT_FOUND * Leave retry at current level --------- Co-authored-by: Hugh Nimmo-Smith --- src/matrixrtc/MatrixRTCSession.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/matrixrtc/MatrixRTCSession.ts b/src/matrixrtc/MatrixRTCSession.ts index 147a6e0a05e..855596b7976 100644 --- a/src/matrixrtc/MatrixRTCSession.ts +++ b/src/matrixrtc/MatrixRTCSession.ts @@ -1189,9 +1189,14 @@ export class MatrixRTCSession extends TypedEventEmitter