Author: toad
Date: 2008-11-28 20:00:34 +0000 (Fri, 28 Nov 2008)
New Revision: 23960

Modified:
   trunk/freenet/src/freenet/io/comm/MessageFilter.java
Log:
Fix nasty race condition in message filter code. We would match a message, set 
the matched flag immediately, and then set the message afterwards, so the 
waiter would sometimes wake up, see the match flag, and return null. Also 
notify at the right time.


Modified: trunk/freenet/src/freenet/io/comm/MessageFilter.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/MessageFilter.java        2008-11-28 
19:58:45 UTC (rev 23959)
+++ trunk/freenet/src/freenet/io/comm/MessageFilter.java        2008-11-28 
20:00:34 UTC (rev 23960)
@@ -169,7 +169,6 @@
        
        public boolean match(Message m) {
                if ((_or != null) && (_or.match(m))) {
-                       _matched = true;
                        return true;
                }
                if ((_type != null) && (!_type.equals(m.getSpec()))) {
@@ -189,7 +188,6 @@
                        }
                }
                if(reallyTimedOut(System.currentTimeMillis())) return false;
-               _matched=true;
                return true;
        }
 
@@ -227,9 +225,11 @@
         return _message;
     }
 
-    public void setMessage(Message message) {
+    public synchronized void setMessage(Message message) {
         //Logger.debug(this, "setMessage("+message+") on "+this, new 
Exception("debug"));
         _message = message;
+        _matched = _message != null;
+        notifyAll();
     }
 
     public int getInitialTimeout() {
@@ -315,7 +315,6 @@
                        // Clear matched before calling callback in case we are 
re-added.
                        if(_callback != null)
                                clearMatched();
-                       notifyAll();
                }
                if(cb != null) {
                        cb.onMatched(msg);

_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to