From: Matt Corallo Date: Sun, 29 Oct 2023 18:40:47 +0000 (+0000) Subject: Fix race in peer connection in C++ demo app X-Git-Tag: v0.0.118.1^2~1 X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=ldk-c-bindings;a=commitdiff_plain;h=df6bde199404ae987e4c3cf8f85865955b3f2ab4 Fix race in peer connection in C++ demo app When we disconnect then immediately reconnect from one peer we may still get the second connection through before the disconnection is handled on the other end, causing connection failures. We fix this here by disconnecting on both ends before reconnecting. --- diff --git a/lightning-c-bindings/demo.cpp b/lightning-c-bindings/demo.cpp index add28af..dc79696 100644 --- a/lightning-c-bindings/demo.cpp +++ b/lightning-c-bindings/demo.cpp @@ -242,6 +242,7 @@ public: // Then disconnect the "main" connection, while another connection is being made. PeerManager_disconnect_by_node_id(&net1, ChannelManager_get_our_node_id(&cm2)); + PeerManager_disconnect_by_node_id(&net2, ChannelManager_get_our_node_id(&cm1)); assert(!socket_connect(node1_handler, ChannelManager_get_our_node_id(&cm2), (sockaddr*)&listen_addr, sizeof(listen_addr))); std::cout << __FILE__ << ":" << __LINE__ << " - " << "Awaiting new connection handshake..." << std::endl;