From: Matt Corallo Date: Fri, 15 Apr 2022 18:50:15 +0000 (+0000) Subject: [Java] Correct trivial race condition in HumanObjectPeerTest X-Git-Tag: v0.0.108.0~4^2~1 X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=ldk-java;a=commitdiff_plain;h=1f7e7b116b79f603bb847a8c8efbb9f1b70200ed [Java] Correct trivial race condition in HumanObjectPeerTest 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`. --- diff --git a/src/test/java/org/ldk/HumanObjectPeerTest.java b/src/test/java/org/ldk/HumanObjectPeerTest.java index 275caf65..64bf97a4 100644 --- a/src/test/java/org/ldk/HumanObjectPeerTest.java +++ b/src/test/java/org/ldk/HumanObjectPeerTest.java @@ -678,9 +678,6 @@ class HumanObjectPeerTestInstance { 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();