Skip to content

Commit df6bde1

Browse files
committed
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.
1 parent fd396ce commit df6bde1

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

lightning-c-bindings/demo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ class PeersConnection {
242242

243243
// Then disconnect the "main" connection, while another connection is being made.
244244
PeerManager_disconnect_by_node_id(&net1, ChannelManager_get_our_node_id(&cm2));
245+
PeerManager_disconnect_by_node_id(&net2, ChannelManager_get_our_node_id(&cm1));
245246
assert(!socket_connect(node1_handler, ChannelManager_get_our_node_id(&cm2), (sockaddr*)&listen_addr, sizeof(listen_addr)));
246247

247248
std::cout << __FILE__ << ":" << __LINE__ << " - " << "Awaiting new connection handshake..." << std::endl;

0 commit comments

Comments
 (0)