Revision: 14983
Author: brainslog
Date: Tue Nov  2 17:28:34 2010
Log: Fixing Diameter stack threads leaking, not being released

Update Issue 2000
Status: Fixed
Committed patch, reviewed by Bartosz
http://code.google.com/p/mobicents/source/detail?r=14983

Modified:
/trunk/servers/diameter/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/fsm/PeerFSMImpl.java /trunk/servers/diameter/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/concurrent/BaseThreadFactory.java /trunk/servers/diameter/core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/fsm/PeerFSMImpl.java

=======================================
--- /trunk/servers/diameter/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/fsm/PeerFSMImpl.java Wed Oct 27 08:23:37 2010 +++ /trunk/servers/diameter/core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/fsm/PeerFSMImpl.java Tue Nov 2 17:28:34 2010
@@ -130,7 +130,7 @@
     "FSM-" + context.getPeerDescription(),
         new Runnable() {
           public void run() {
-            while (true) {
+            while (executor != null) {
               StateEvent event;
               try {
                 event = eventQueue.poll(100, TimeUnit.MILLISECONDS);
@@ -202,24 +202,24 @@
   }

public boolean handleEvent(StateEvent event) throws InternalError, OverloadException { - if (state.getPublicState() == PeerState.DOWN && event.encodeType(EventTypes.class) == EventTypes.START_EVENT) { + //if (state.getPublicState() == PeerState.DOWN && event.encodeType(EventTypes.class) == EventTypes.START_EVENT) {
+    if(executor == null) {
       runQueueProcessing();
     }

if (event.getData() != null && DiameterMessageValidator.getInstance().isOn()) {
       boolean incoming = event.getType() == EventTypes.RECEIVE_MSG_EVENT;
-               if(incoming)
-               {
-                       //outgoing are done elswhere: see BaseSessionImpl
-                       try{
- DiameterMessageValidator.getInstance().validate((Message) event.getData(), incoming);
-                       }catch(JAvpNotAllowedException e)
-                       {
-                               logger.error("Failed to validate incoming 
message.", e);
-                               return false;
-                       }
-               }
-               }
+      if(incoming) {
+        // outgoing are done elsewhere: see BaseSessionImpl
+        try{
+ DiameterMessageValidator.getInstance().validate((Message) event.getData(), incoming);
+        }
+        catch(JAvpNotAllowedException e) {
+          logger.error("Failed to validate incoming message.", e);
+          return false;
+        }
+      }
+    }

     boolean rc;
     try {
=======================================
--- /trunk/servers/diameter/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/concurrent/BaseThreadFactory.java Tue Feb 2 02:53:45 2010 +++ /trunk/servers/diameter/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/concurrent/BaseThreadFactory.java Tue Nov 2 17:28:34 2010
@@ -10,30 +10,31 @@
   private ThreadGroup threadGroup;
   private String threadPoolName;
   private AtomicInteger count = new AtomicInteger(0);
-  private int maxCount;
+ // ammendonca: factory should not have this kind of limitations, it's not a pool
+  // private int maxCount;

   public BaseThreadFactory(String threadPoolName) {
     this.threadPoolName = threadPoolName;
-    this.maxCount = Integer.MAX_VALUE;
+    // this.maxCount = Integer.MAX_VALUE;
     this.threadGroup = new ThreadGroup("jd " + threadPoolName + " group");
   }

   public BaseThreadFactory(String threadPoolName, int maxCount) {
     this(threadPoolName);
-    this.maxCount = maxCount;
+    // this.maxCount = maxCount;
   }

   public Thread newThread(Runnable runnable) {
-    if (count.get() > maxCount) {
- throw new RuntimeException("Can not create thread (count=" + count.get() + ", max=" + maxCount + ")");
-    }
+    // if (count.get() > maxCount) {
+ // throw new RuntimeException("Can not create thread (count=" + count.get() + ", max=" + maxCount + ")");
+    // }
return new Thread(threadGroup, runnable, threadPoolName + "-" + count.getAndIncrement());
   }

   public Thread newThread(String namePrefix, Runnable runnable) {
-    if (count.get() > maxCount) {
- throw new RuntimeException("Can not create thread (count=" + count.get() + ", max=" + maxCount + ")");
-    }
+    // if (count.get() > maxCount) {
+ // throw new RuntimeException("Can not create thread (count=" + count.get() + ", max=" + maxCount + ")");
+    // }
return new Thread(threadGroup, runnable, namePrefix + "-" + count.getAndIncrement());
   }

=======================================
--- /trunk/servers/diameter/core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/fsm/PeerFSMImpl.java Wed Oct 27 08:23:37 2010 +++ /trunk/servers/diameter/core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/fsm/PeerFSMImpl.java Tue Nov 2 17:28:34 2010
@@ -209,6 +209,9 @@
           {
             public void entryAction() {
               setTimer(0);
+              if(!context.isRestoreConnection()) {
+                executor = null;
+              }
             }

             public boolean processEvent(StateEvent event) {

Reply via email to