fix(matrix): tune sync transport timeouts

This commit is contained in:
Mikhail Putilovskij 2026-04-01 01:49:16 +03:00
parent 14c091b5f5
commit 6a843e8036

View file

@ -8,6 +8,7 @@ from pathlib import Path
import structlog
from nio import (
AsyncClient,
AsyncClientConfig,
InviteMemberEvent,
MatrixRoom,
ReactionEvent,
@ -186,14 +187,23 @@ async def main() -> None:
password = os.environ.get("MATRIX_PASSWORD")
token = os.environ.get("MATRIX_ACCESS_TOKEN")
db_path = os.environ.get("MATRIX_DB_PATH", "lambda_matrix.db")
store_path = os.environ.get("MATRIX_STORE_PATH", "matrix_store")
if not homeserver or not user_id:
raise RuntimeError("MATRIX_HOMESERVER and MATRIX_USER_ID are required")
client_config = AsyncClientConfig(
request_timeout=120,
max_timeouts=12,
max_limit_exceeded=20,
backoff_factor=0.5,
max_timeout_retry_wait_time=15,
)
client = AsyncClient(
homeserver,
user=user_id,
device_id=device_id,
store_path=os.environ.get("MATRIX_STORE_PATH"),
store_path=store_path,
config=client_config,
)
runtime = build_runtime(store=SQLiteStore(db_path), client=client)
if token:
@ -206,7 +216,13 @@ async def main() -> None:
client.add_event_callback(bot.on_reaction, ReactionEvent)
client.add_event_callback(bot.on_member, (InviteMemberEvent, RoomMemberEvent))
logger.info("Matrix bot starting")
logger.info(
"Matrix bot starting",
homeserver=homeserver,
user_id=user_id,
store_path=store_path,
request_timeout=client_config.request_timeout,
)
try:
await client.sync_forever(timeout=30000)
finally: