Outbound group sessions are invalidated upon reception of a duplicate state event

Abierto
#169 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
python
Área
backend

Línea de trabajo

Comienza con update_state() en mautrix/client/state_store/abstract.py y su registro en mautrix/client/client.py; después, sigue handle_member_event() en mautrix/crypto/machine.py y su registro allí. Compara las rutas de carga y comparación concurrentes con los commits referenciados. Se considera terminado cuando los eventos de Membership duplicados ya no invaliden las sesiones de grupo salientes, mientras que los cambios de estado genuinos sí lo sigan haciendo.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Mautrix uses lazy membership loading, which causes synapse to oftentimes send state events to the client, that the client has already received. Upon reception of a state event, mautrix invalidates all outbound group sessions. This is the correct thing to do, but because synapse frequently sends duplicate state events, mautrix invalidates outbound group sessions all the time.

A fix for this has first been implemented in 72fb0f61f2a8cf8f062ddb8bacaa98ef4cbd0aa5. This fix relies on storing the most recent membership event as an attribute of the event and then later comparing this stored event to the received event and ignoring the received event if they are equal:
https://github.com/mautrix/python/blob/3e22e6192e2a9d208b9e7ea159b2169daa60a1ce/mautrix/client/state_store/abstract.py#L146-L148
https://github.com/mautrix/python/blob/3e22e6192e2a9d208b9e7ea159b2169daa60a1ce/mautrix/crypto/machine.py#L193-L200

The problem is, that loading the most recent membership event and comparing the stored membership event happens in different event handlers, which are executed concurrently.
The most recent membership event is loaded in the update_state() event handler, which is registered here:
https://github.com/mautrix/python/blob/3e22e6192e2a9d208b9e7ea159b2169daa60a1ce/mautrix/client/client.py#L31

Comparing the received membership event against the most recent one happens in handle_member_event(), which is registered here:
https://github.com/mautrix/python/blob/3e22e6192e2a9d208b9e7ea159b2169daa60a1ce/mautrix/crypto/machine.py#L109
While the update_state() handler is executed first, execution is interrupted once the most recent membership event is loaded via await self.get_member(), as this loads the event from the database, which takes some time. In the meantime, handle_member_event() becomes active and attempts to compare the received membership event against the most recent one, which hasn't yet been loaded from the database. As a result, the comparison fails and the outbound session is invalidated.

I implemented a hacky fix for this in https://github.com/jkhsjdhjs/mautrix-python/commit/e7c1921fb8f52549baf09ed2784fe46573964911, as I don't know a good way to fix this properly.

Lenguaje dominante
Python
Estrellas
249
Forks
84
Métricas de merge de PR
Sin PR fusionados en 30 d

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de mautrix/python

Todos los issues de mautrix/python

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.