UNIQUE constraint failed: peer.address, peer.udp_port when saving DHT nodes
Open
Nobody has claimed this yet.
area: DHT
needs: exploration
type: bug
- Dominant language
- Python
- Stars
- 7.2k
- Forks
- 493
- PR merge metrics
- No merged PRs in 30d
Description
Left a script running and got that on shutdown. Needs investigation, but looks rare
2021-12-14 16:17:34,063 ERROR asyncio:1608: Task exception was never retrieved
future: <Task finished coro=<Node.refresh_node() done, defined at /home/user/lbry/lbry-sdk/lbry/dht/node.py:45> exception=IntegrityError('UNIQUE constraint failed: peer.address, peer.udp_port')>
Traceback (most recent call last):
File "/home/user/lbry/lbry-sdk/lbry/dht/node.py", line 86, in refresh_node
hash_value = bytes.fromhex(blob_hash)
File "/home/user/lbry/lbry-sdk/lbry/extras/daemon/storage.py", line 931, in save_kademlia_peers
return await self.db.run(_save_kademlia_peers)
File "/home/user/lbry/lbry-sdk/lbry/wallet/database.py", line 209, in run
self.writer_executor, lambda: self.__run_transaction(fun, *args, **kwargs)
File "/usr/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/user/lbry/lbry-sdk/lbry/wallet/database.py", line 209, in <lambda>
self.writer_executor, lambda: self.__run_transaction(fun, *args, **kwargs)
File "/home/user/lbry/lbry-sdk/lbry/wallet/database.py", line 222, in __run_transaction
result = fun(self.writer_connection, *args, **kwargs) # type: ignore
File "/home/user/lbry/lbry-sdk/lbry/extras/daemon/storage.py", line 929, in _save_kademlia_peers
((binascii.hexlify(p.node_id), p.address, p.udp_port, p.tcp_port) for p in peers)
sqlite3.IntegrityError: UNIQUE constraint failed: peer.address, peer.udp_port
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with lbry/dht/node.py:45 and refresh_node(), then trace the save path through lbry/extras/daemon/storage.py:929-931 and the peer schema or related tests. Reproduce or isolate the shutdown-time duplicate address and UDP port condition, and add coverage showing that saving Kademlia peers no longer raises the reported UNIQUE constraint error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, sqlite
- Domain
- databases, distributed-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100