maubot
maubot copied to clipboard
error on every message the bot(s) receive: duplicate key value violates unique constraint "crypto_device_pkey"
Hi, I installed maubot yesterday and it worked fine when run from the terminal. I then created a systemd-service (see below) to start the bot on boot and disconnected from a terminal. It works. But later I see a lot of Tracebacks in the maubot logs. Multiple Bots created multiple Tracebacks in this case. The error is thrown when someone (even another bot) sends a message in a room with bots. Do you know what the problem might be?
Failed to run handler
Traceback (most recent call last):
File "/home/maubot/maubot/lib/python3.9/site-packages/mautrix/client/syncer.py", line 200, in _catch_errors
await handler(data)
File "/home/maubot/maubot/lib/python3.9/site-packages/mautrix/crypto/machine.py", line 102, in handle_device_lists
await self._fetch_keys(device_lists.changed, include_untracked=False)
File "/home/maubot/maubot/lib/python3.9/site-packages/mautrix/crypto/device_lists.py", line 57, in _fetch_keys
await self.crypto_store.put_devices(user_id, new_devices)
File "/home/maubot/maubot/lib/python3.9/site-packages/mautrix/crypto/store/asyncpg/store.py", line 263, in put_devices
await conn.copy_records_to_table("crypto_device", records=data, columns=columns)
File "/home/maubot/maubot/lib/python3.9/site-packages/asyncpg/connection.py", line 923, in copy_records_to_table
return await self._copy_in_records(
File "/home/maubot/maubot/lib/python3.9/site-packages/asyncpg/connection.py", line 1048, in _copy_in_records
return await self._protocol.copy_in(
File "asyncpg/protocol/protocol.pyx", line 508, in copy_in
asyncpg.exceptions.UniqueViolationError: duplicate key value violates unique constraint "crypto_device_pkey"
DETAIL: Key (user_id, device_id)=(@<USERNAME>:hs-bremerhaven.de, <SESSION_ID) already exists.
# /usr/local/lib/systemd/system/maubot.service
[Unit]
Description=maubot service
After=matrix-synapse.service
[Service]
User=maubot
Group=maubot
WorkingDirectory=/home/maubot/maubot
ExecStart=/home/maubot/maubot/bin/python3 -m maubot
KillSignal=SIGINT
Environment="VIRTUAL_ENV=/home/maubot/maubot"
Environment="PATH=/home/maubot/maubot/bin:/usr/local/bin:/usr/bin:/bin"
[Install]
WantedBy=multi-user.target
I'm seeing this now, even after resetting the DB. It seems to be a race condition for which bot client updates the device list first.