telegram icon indicating copy to clipboard operation
telegram copied to clipboard

Feedback loop of typing indicators when Double-puppeting

Open ShadowJonathan opened this issue 5 years ago • 2 comments

Previous content: This has been something that was noted in my chat today, where someone mentioned i was "writing an essay" as my typing indicator has been running for multiple minutes, while in reality i was offline.

Investigating the issue this afternoon, it seems like when the time between typing (hitting the first keystroke) and sending is under a second, the bridge would somehow enter a perpetual feedback loop (of some sorts) where it'd keep sending typing indicator requests to the matrix server, and other members of the chat attesting the same is happening on telegram's side.

I have my account double-puppetted, some members have their telegram account linked, but not their matrix account, this issue seems to only happen when typing-and-sending from telegram in a quick fashion.

(This is marked as a "proto issue" because i dont have enough data or time to look into this, but i want to signal the issue anyways)

New content:

It seems that the matrix bridge fails to ignore its own typing indicator events when mirroring them, not tracking where these come from, and when typing has gone on for long enough, it could enter a feedback loop in which it's difficult to get out of, resulting in the bridge responding with a typing event from both sides of the bridge, and sending to another one, entering in a loop.

Fix: Add a "lock" to make sure the bridge does not echo typing events, where the lock would prevent typing events to not be echoed back to the side A for 2x the typing duration, every time a typing event is sent from side B, the countdown would refresh, and prevent typing events from side B to be propagated.

At worst (when a user suddenly switches between telegram and matrix mid-typing), it would result in a period of 1x the typing duration where (legitimate) typing events from side B are blocked.

ShadowJonathan avatar Sep 06 '20 19:09 ShadowJonathan

~~It seems that sometimes .portal.PortalMatrix.set_typing() does not receive a SendMessageCancelAction properly to cancel the typing action telegram-side, and it's also possible telegram does not time-out typing events eventually, but that clients have to do this.~~

~~Info found here: https://stackoverflow.com/a/54728296~~

Edit: Nevermind, this is disproven through manholing and manually triggering a typing event

ShadowJonathan avatar Sep 12 '20 11:09 ShadowJonathan

After doing some more digging, it seems that telegram is waiting more than 5 seconds before echoing the typing event back to the bridge, in which case it's impossible to short-cut the feedback loop it creates as a result, as 5 seconds is the default timeout on the state object tracking current "typing" events.

ShadowJonathan avatar Sep 12 '20 14:09 ShadowJonathan