[Java] Correct trivial race condition in HumanObjectPeerTest
authorMatt Corallo <git@bluematt.me>
Fri, 15 Apr 2022 18:50:15 +0000 (18:50 +0000)
committerMatt Corallo <git@bluematt.me>
Fri, 15 Apr 2022 18:52:57 +0000 (18:52 +0000)
On my (very slow) old armv7 device, HumanObjectPeerTest can fail as
`maybe_exchange_peer_messages` will set `ran = false` *after* a
message is added to the runqueue, but before it runs, then when we
call `process_events` there will be no events to process, then
before we get into the `runqueue` `synchronized` block the message
will be delivered, causing us to think we're done, even though
there are now events pending. Because going around the loop twice
is free, we should just not set `ran` to false at the top of
`maybe_exchange_peer_messages`.

src/test/java/org/ldk/HumanObjectPeerTest.java

index 275caf650dfc6f9269fa22455b1bfe7e2081d10d..64bf97a4340df60b90ee27bdc8664951b2740145 100644 (file)
@@ -678,9 +678,6 @@ class HumanObjectPeerTestInstance {
 
     void maybe_exchange_peer_messages(Peer peer1, Peer peer2) {
         if (!use_nio_peer_handler) {
 
     void maybe_exchange_peer_messages(Peer peer1, Peer peer2) {
         if (!use_nio_peer_handler) {
-            synchronized (runqueue) {
-                ran = false;
-            }
             while (true) {
                 peer1.peer_manager.process_events();
                 peer2.peer_manager.process_events();
             while (true) {
                 peer1.peer_manager.process_events();
                 peer2.peer_manager.process_events();