The following pattern was duplicated in CConnman:
cpp lock create a copy of vNodes, add a reference to each one unlock ... use the copy ... lock release each node from the copy unlock
Put that code in a RAII helper that reduces it to:
cpp create snapshot "snap" ... use the copy ... // release happens when "snap" goes out of scope
This is a partial backport of core#21943
https://github.com/bitcoin/bitcoin/pull/21943/commits/75e8bf55f5a014faada7712a9640dc35e8c86f15