Good point. Though, I was just checking my container that was running this patch in a loop. I think this is still racy, because getpeerinfo is updated before the debug log. So my patch will intermittently fail:
0 test 2026-02-14T09:37:34.797636Z TestFramework (INFO): Test sendmsgtopeer
1 test 2026-02-14T09:37:34.797727Z TestFramework (DEBUG): Send a valid message
2 node1 2026-02-14T09:37:34.797858Z [http] [httpserver.cpp:233] [http_request_cb] [http] Received a POST request for / from 127.0.0.1:33442
3 node1 2026-02-14T09:37:34.797891Z [http_pool_1] [rpc/request.cpp:243] [parse] [rpc] ThreadRPCServer method=getpeerinfo user=__cookie__
4 node0 2026-02-14T09:37:34.798363Z [http] [httpserver.cpp:233] [http_request_cb] [http] Received a POST request for / from 127.0.0.1:52144
5 node0 2026-02-14T09:37:34.798411Z [http_pool_1] [rpc/request.cpp:243] [parse] [rpc] ThreadRPCServer method=sendmsgtopeer user=__cookie__
6 node0 2026-02-14T09:37:34.798449Z [http_pool_1] [net.cpp:4074] [PushMessage] [net] sending addr (3 bytes) peer=0
7 node1 2026-02-14T09:37:34.798737Z [http] [httpserver.cpp:233] [http_request_cb] [http] Received a POST request for / from 127.0.0.1:33442
8 node1 2026-02-14T09:37:34.798793Z [http_pool_0] [rpc/request.cpp:243] [parse] [rpc] ThreadRPCServer method=getpeerinfo user=__cookie__
9 test 2026-02-14T09:37:34.799214Z TestFramework (ERROR): Unexpected exception
10 Traceback (most recent call last):
11 File "/b-c/test/functional/test_framework/test_framework.py", line 142, in main
12 self.run_test()
13 ~~~~~~~~~~~~~^^
14 File "/b-c/bld-cmake/test/functional/rpc_net.py", line 93, in run_test
15 self.test_sendmsgtopeer()
16 ~~~~~~~~~~~~~~~~~~~~~~~^^
17 File "/b-c/bld-cmake/test/functional/rpc_net.py", line 422, in test_sendmsgtopeer
18 with self.nodes[1].assert_debug_log(expected_msgs=["received: addr"]):
19 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20 File "/usr/lib/python3.13/contextlib.py", line 148, in __exit__
21 next(self.gen)
22 ~~~~^^^^^^^^^^
23 File "/b-c/test/functional/test_framework/test_node.py", line 584, in assert_debug_log
24 self._raise_assertion_error(f'Expected message(s) {remaining_expected!s} '
25 ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26 f'not found in log:\n\n{join_log(log)}\n\n')
27 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
28 File "/b-c/test/functional/test_framework/test_node.py", line 229, in _raise_assertion_error
29 raise AssertionError(self._node_msg(msg))
30 AssertionError: [node 1] Expected message(s) ['received: addr'] not found in log:
31 - 2026-02-14T09:37:34.798737Z [http] [httpserver.cpp:233] [http_request_cb] [http] Received a POST request for / from 127.0.0.1:33442
32 - 2026-02-14T09:37:34.798793Z [http_pool_0] [rpc/request.cpp:243] [parse] [rpc] ThreadRPCServer method=getpeerinfo user=__cookie__
33 node1 2026-02-14T09:37:34.799316Z [msghand] [net_processing.cpp:3555] [ProcessMessage] [net] received: addr (3 bytes) peer=0
34 node1 2026-02-14T09:37:34.799433Z [msghand] [net_processing.cpp:5257] [ProcessMessages] [net] ProcessMessages(addr, 3 bytes): Exception 'DataStream::read(): end of data: iostream error' (NSt8ios_base7failureB5cxx11E) caught
35 test 2026-02-14T09:37:34.803544Z TestFramework (DEBUG): Closing down network thread
36 test 2026-02-14T09:37:34.853858Z TestFramework (INFO): Not stopping nodes as test failed. The dangling processes will be cleaned up later.
37 test 2026-02-14T09:37:34.854000Z TestFramework (WARNING): Not cleaning up dir /tmp/test_runner_₿_🏃_20260214_092501/rpc_net_152
38 test 2026-02-14T09:37:34.854061Z TestFramework (ERROR): Test failed. Test logging available at /tmp/test_runner_₿_🏃_20260214_092501/rpc_net_152/test_framework.log
39 test 2026-02-14T09:37:34.854196Z TestFramework (ERROR):
40 test 2026-02-14T09:37:34.854294Z TestFramework (ERROR): Hint: Call /b-c/test/functional/combine_logs.py '/tmp/test_runner_₿_🏃_20260214_092501/rpc_net_152' to consolidate all logs
41 test 2026-02-14T09:37:34.854339Z TestFramework (ERROR):
42 test 2026-02-14T09:37:34.854379Z TestFramework (ERROR): If this failure happened unexpectedly or intermittently, please file a bug and provide a link or upload of the combined log.
43 test 2026-02-14T09:37:34.854449Z TestFramework (ERROR): https://github.com/bitcoin/bitcoin/issues
44 test 2026-02-14T09:37:34.854491Z TestFramework (ERROR):
I think the only reliable way here would be a sync-with-ping, like in all other python p2p connections.