lightningdevkit / lightning-liquidity

Other
27 stars 17 forks source link

Fix deadlock on deserialization failure #116

Closed tnull closed 8 months ago

tnull commented 8 months ago

Previously, we introduced disconnecting a counterparty who sends us bogus messages that we're unable to parse. However, before we disconnect we also send out a last LSPSMessage::Invalid in the hopes that the counterparty understands this.

However, when we added this logic we unfortunately overlooked that we lock the request_id_to_method_map Mutex for parsing the message, but also try to lock when the PeerHandler calls get_and_clear_pending_msg.

Here, we avoid the resulting deadlock by dropping the lock as soon as it's not required anymore after parsing.

In a second commit, we avoid unnecessary locking of request_ids_and_methods_map in get_and_clear_pending_msg and remove a potentially dangerous (if we ever were to fail serialization for some reason) unwrap.