From 5f0a4416db4339176e31fab5f4b7b79f4e7cf20b Mon Sep 17 00:00:00 2001 From: Jeffrey Wilcke Date: Fri, 20 Nov 2015 19:23:55 +0100 Subject: whisper: fixed broadcast race Whisper's expire and broadcast loops happen in two separate go routines. Whenever an envelope is being expired it's removed from the set of envelopes and it looses all information about the envelope, including the "known hash". After the envelope has been removed it can be re-accepted by a broadcasting peer putting back the envelope in the set of envelopes. Since the envelope broadcast loop is separate of the expire loop expired messages may be broadcast to other peer, resulting in messages **never** being dropped. This PR includes an expire check before adding new messages to the set of envelopes. --- whisper/whisper_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'whisper/whisper_test.go') diff --git a/whisper/whisper_test.go b/whisper/whisper_test.go index 1a9a8667a..b83ce0fe7 100644 --- a/whisper/whisper_test.go +++ b/whisper/whisper_test.go @@ -207,4 +207,13 @@ func TestMessageExpiration(t *testing.T) { if found { t.Fatalf("message not expired from cache") } + + node.add(envelope) + node.poolMu.RLock() + _, found = node.messages[envelope.Hash()] + node.poolMu.RUnlock() + if found { + t.Fatalf("message was added to cache") + } + } -- cgit