From aa95a3957edf35ece1fa31ec0d732601228272be Mon Sep 17 00:00:00 2001 From: daywalker90 Date: Tue, 15 Sep 2026 19:32:33 +0200 Subject: [PATCH] tests: fix flake in test_dataloss_protection l2 detects the data loss and sends l1 an "Awaiting unilateral close" error (after the channeld's 1 second delay), which l1 must receive to drop to chain. But l1's channeld normally sends a warning and exits first; if l2's error arrives before l1's connectd has torn that subd down it is routed to the dying channeld and lost, so l1 never sees it and we time out waiting for: l1.daemon.wait_for_log("They sent ERROR.*Awaiting unilateral close") Reconnect if we don't see it: channel->error is resent when the peer reconnects, so l1 gets the error and drops to chain. We may already be disconnected, in which case disconnect() fails with "Peer not connected": that's fine, connect() is what matters. This restores the workaround the test had before 6fdaec313 replaced it with the channeld sleep. Changelog-None --- tests/test_connection.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/test_connection.py b/tests/test_connection.py index baa3f1345464..bf1a9b5cda6e 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -3184,8 +3184,20 @@ def test_dataloss_protection(node_factory, bitcoind): assert not l2.daemon.is_in_log('sendrawtx exit 0', start=l2.daemon.logsearch_start) - # l1 should receive error and drop to chain - l1.daemon.wait_for_log("They sent ERROR.*Awaiting unilateral close") + # l1 should receive error and drop to chain. Usually it arrives when l1 + # has no channeld (so lightningd logs "They sent ERROR"), but if l1's + # channeld has not exited yet the error is routed to it and gets lost + # when it dies. Reconnect to make l2 resend it: channel->error is sent + # again when the peer reconnects. + try: + l1.daemon.wait_for_log("They sent ERROR.*Awaiting unilateral close", timeout=10) + except TimeoutError: + # The peer may already have gone; connect() below is what matters. + try: + l1.rpc.disconnect(l2.info['id'], force=True) + except RpcError as err: + assert "Peer not connected" in err.error['message'] + l1.rpc.connect(l2.info['id'], 'localhost', l2.port) l1.wait_for_channel_onchain(l2.info['id']) closetxid = only_one(bitcoind.rpc.getrawmempool(False))