# Buggy code
async def schedule_segment(
    self, parent_header: BlockHeader, gap_length: int, skeleton_peer: TChainPeer
) -> None:
    """
    :param parent_header: the parent of the gap to fill
    :param gap_length: how long is the header gap
    :param skeleton_peer: the peer that provided the parent_header - will not use to fill gaps
    """
    await self.wait(
        self._filler_header_tasks.add(((parent_header, gap_length, skeleton_peer),))
    )


# Traceback (eth_utils.exceptions.ValidationError)
ERROR  09-09 11:44:41  ETHHeaderChainSyncer  Unexpected error in <trinity.protocol.eth.sync.ETHHeaderChainSyncer object at 0x7fc3dfd1beb8>, exiting
Traceback (most recent call last):
File "/home/ubuntu/trinity/p2p/service.py", line 118, in run
File "/home/ubuntu/trinity/trinity/sync/common/headers.py", line 866, in _run
File "/home/ubuntu/trinity/p2p/cancellable.py", line 20, in wait
return await self.wait_first(awaitable, token=token, timeout=timeout)
File "/home/ubuntu/trinity/p2p/cancellable.py", line 43, in wait_first
return await token_chain.cancellable_wait(*awaitables, timeout=timeout)
File "/home/ubuntu/trinity/venv/lib/python3.6/site-packages/cancel_token/token.py", line 178, in cancellable_wait
return done.pop().result()
File "/home/ubuntu/trinity/trinity/sync/common/headers.py", line 880, in _build_skeleton
File "/home/ubuntu/trinity/trinity/sync/common/headers.py", line 961, in _full_skeleton_sync
File "/home/ubuntu/trinity/p2p/cancellable.py", line 20, in wait
return await self.wait_first(awaitable, token=token, timeout=timeout)
File "/home/ubuntu/trinity/p2p/cancellable.py", line 43, in wait_first
return await token_chain.cancellable_wait(*awaitables, timeout=timeout)
File "/home/ubuntu/trinity/venv/lib/python3.6/site-packages/cancel_token/token.py", line 178, in cancellable_wait
return done.pop().result()
File "/home/ubuntu/trinity/trinity/sync/common/headers.py", line 596, in schedule_segment
File "/home/ubuntu/trinity/p2p/cancellable.py", line 20, in wait
return await self.wait_first(awaitable, token=token, timeout=timeout)
File "/home/ubuntu/trinity/p2p/cancellable.py", line 43, in wait_first
return await token_chain.cancellable_wait(*awaitables, timeout=timeout)
File "/home/ubuntu/trinity/venv/lib/python3.6/site-packages/cancel_token/token.py", line 178, in cancellable_wait
return done.pop().result()
File "/home/ubuntu/trinity/trinity/_utils/datastructures.py", line 160, in add
eth_utils.exceptions.ValidationError: Duplicate tasks detected: {(<eth.rlp.headers.BlockHeader object at 0x7fc39a1aee80>, 192, ETHPeer <Node(0xd64684e7a34c4f0aaaa07e1f6143ec91610b99b120b441387356def326890b40867a4aa4384af7fe4088858c161a05efb61499c35d194b4f46c4a0cac82f2ee2@35.193.221.102:40780)>)} are already present in the queue

# Fixed code
async def schedule_segment(
    self, parent_header: BlockHeader, gap_length: int, skeleton_peer: TChainPeer
) -> None:
    """
    :param parent_header: the parent of the gap to fill
    :param gap_length: how long is the header gap
    :param skeleton_peer: the peer that provided the parent_header - will not use to fill gaps
    """
    try:
        await self.wait(
            self._filler_header_tasks.add(((parent_header, gap_length, skeleton_peer),))
        )
    except ValidationError as exc:
        self.logger.debug(
            "Tried to re-add a duplicate list of headers to the download queue: %s",
            exc,
        )