Skip to content

Commit 92aef65

Browse files
committed
Stop bridge if crypto sync fails
1 parent 59c2146 commit 92aef65

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

mautrix/bridge/e2ee.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from mautrix import __optional_imports__
1313
from mautrix.appservice import AppService
14-
from mautrix.client import Client, SyncStore
14+
from mautrix.client import Client, InternalEventType, SyncStore
1515
from mautrix.crypto import CryptoStore, OlmMachine, PgCryptoStore, RejectKeyShare, StateStore
1616
from mautrix.errors import EncryptionError, SessionNotFound
1717
from mautrix.types import (
@@ -100,8 +100,14 @@ def __init__(
100100
default_retry_count=default_http_retry_count,
101101
)
102102
self.crypto = OlmMachine(self.client, self.crypto_store, self.state_store)
103+
self.client.add_event_handler(InternalEventType.SYNC_STOPPED, self._exit_on_sync_fail)
103104
self.crypto.allow_key_share = self.allow_key_share
104105

106+
async def _exit_on_sync_fail(self, data) -> None:
107+
if data["error"]:
108+
self.log.critical("Exiting due to crypto sync error")
109+
sys.exit(32)
110+
105111
async def allow_key_share(self, device: DeviceIdentity, request: RequestedKeyInfo) -> bool:
106112
require_verification = self.key_sharing_config.get("require_verification", True)
107113
allow = self.key_sharing_config.get("allow", False)

0 commit comments

Comments
 (0)