@@ -4368,6 +4368,53 @@ def test_multichan(node_factory, executor, bitcoind):
43684368 assert l2 .rpc .listhtlcs (scid12 )['htlcs' ] == l1htlcs
43694369
43704370
4371+ def test_mutual_reconnect_race (node_factory , executor , bitcoind ):
4372+ """Test simultaneous reconnect between nodes"""
4373+ l1 , l2 = node_factory .line_graph (2 , opts = {'may_reconnect' : True ,
4374+ 'dev-no-reconnect' : None })
4375+
4376+ def send_many_payments ():
4377+ for i in range (20 ):
4378+ time .sleep (0.5 )
4379+ inv = l2 .rpc .invoice (
4380+ 100 - i , # Ensure prior chanhints don't block us
4381+ "label-" + str (i ),
4382+ "desc"
4383+ )['bolt11' ]
4384+ try :
4385+ l1 .rpc .pay (inv )
4386+ except RpcError :
4387+ pass
4388+
4389+ # Send a heap of payments, while reconnecting...
4390+ fut = executor .submit (send_many_payments )
4391+
4392+ for i in range (10 ):
4393+ try :
4394+ l1 .rpc .disconnect (l2 .info ['id' ], force = True )
4395+ except RpcError :
4396+ pass
4397+ time .sleep (1 )
4398+ # Aim for both at once!
4399+ executor .submit (l1 .rpc .connect , l2 .info ['id' ], 'localhost' , l2 .port )
4400+ executor .submit (l2 .rpc .connect , l1 .info ['id' ], 'localhost' , l1 .port )
4401+
4402+ # Wait for things to settle down, then make sure we're actually connected.
4403+ # Naively, you'd think we should be, but in fact, two connects which race
4404+ # can (do!) result in both disconnecting, thinking the other side is more
4405+ # recent.
4406+ time .sleep (1 )
4407+ if not only_one (l1 .rpc .listpeers (l2 .info ['id' ])['peers' ])['connected' ]:
4408+ l1 .rpc .connect (l2 .info ['id' ], 'localhost' , l2 .port )
4409+
4410+ # Now payments should finish!
4411+ fut .result (TIMEOUT )
4412+
4413+ wait_for (lambda : only_one (l1 .rpc .listpeers (l2 .info ['id' ])['peers' ])['connected' ])
4414+ inv = l2 .rpc .invoice (100000000 , "invoice4" , "invoice4" )
4415+ l1 .rpc .pay (inv ['bolt11' ])
4416+
4417+
43714418def test_no_reconnect_awating_unilateral (node_factory , bitcoind ):
43724419 l1 , l2 = node_factory .line_graph (2 , opts = {'may_reconnect' : True })
43734420 l2 .stop ()
0 commit comments