There is currently no real-world way to trigger this issue, but this will become possible once the node/peer binding is completed.
When a peer is removed, the nodes are removed as well unless they have an inflight query. This is done so if the node is bound to another peer at a later time is is not overqueried. But the the code updating the node will only work when the node moves from an existing peer to another existing one, and assert if the previous peer no longer exists.
This diff prevents this assertion and add a test that would raise the assertion before this patch.
Ref T1634.