From 2f72eb64d7ba115f26101bed42695f5cd4b01bf1 Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Mon, 13 Feb 2012 23:32:14 +0100 Subject: [PATCH] Note that there is a race in MockNetworkConnection. Fixing it will have to wait until I am less tired. --- .../google/bitcoin/core/MockNetworkConnection.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/com/google/bitcoin/core/MockNetworkConnection.java b/tests/com/google/bitcoin/core/MockNetworkConnection.java index 745fe9f9..3465871f 100644 --- a/tests/com/google/bitcoin/core/MockNetworkConnection.java +++ b/tests/com/google/bitcoin/core/MockNetworkConnection.java @@ -65,12 +65,17 @@ public class MockNetworkConnection implements NetworkConnection { try { // Notify popOutbound() that the network thread is now waiting to receive input. This is needed because // otherwise it's impossible to tell apart "thread decided to not write any message" from "thread is still - // working on it" in a race-free manner. + // working on it". synchronized (this) { waitingToRead = true; notifyAll(); } Object o = inboundMessageQ.take(); + // BUG 141: There is a race at this point: inbound queue can be empty at the same time as waitingToRead is + // true, which is taken as an indication that all messages have been processed. In fact they have not. + synchronized (this) { + waitingToRead = false; + } if (o instanceof IOException) { throw (IOException) o; } else if (o instanceof ProtocolException) { @@ -84,10 +89,6 @@ public class MockNetworkConnection implements NetworkConnection { } } catch (InterruptedException e) { throw new IOException(e.getMessage()); - } finally { - synchronized (this) { - waitingToRead = false; - } } }