lbryio / lbryio/lbry-sdk

UNIQUE constraint failed: peer.address, peer.udp_port when saving DHT nodes

Open
#3,522 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.