Ignore lockorder violation on same callsite with different construction
authorWilmer Paulino <wilmer@wilmerpaulino.com>
Wed, 22 Mar 2023 18:46:05 +0000 (11:46 -0700)
committerWilmer Paulino <wilmer@wilmerpaulino.com>
Wed, 29 Mar 2023 00:27:47 +0000 (17:27 -0700)
commit2166c8a2c46f9a8c50c3dd909fc47a9558a8355b
tree2d8011082121ecb647152efc74d9619a816e33e7
parent04ee9486434f23ab73d60f5be06bfea426db0060
Ignore lockorder violation on same callsite with different construction

As long as the lock order on such locks is still valid, we should allow
them regardless of whether they were constructed at the same location or
not. Note that we can only really enforce this if we require one lock
call per line, or if we have access to symbol columns (as we do on Linux
and macOS). We opt for a smaller patch by relying on the latter.

This was previously triggered by some recent test changes to
`test_manager_serialize_deserialize_inconsistent_monitor`. When the
test ends and a node is dropped causing us to persist each, we'd detect
a possible lockorder violation deadlock across three different `Mutex`
instances that are held at the same location when serializing our
`per_peer_states` in `ChannelManager::write`.

The presumed lockorder violation happens because the first `Mutex` held
shares the same construction location with the third one, while the
second `Mutex` has a different construction location. When we hold the
second one, we consider the first as a dependency, and then consider the
second as a dependency when holding the third, causing a circular
dependency (since the third shares the same construction location as the
first).

This isn't considered a lockorder violation that could result in a
deadlock as the comment suggests inline though, since we are under a
dependent write lock which no one else can have access to.
lightning/src/sync/debug_sync.rs